예제 #1
0
    from pysqlite2 import dbapi2 as sqlite
except ImportError:
    try:
        from sqlite3 import dbapi2 as sqlite
    except ImportError:
        sqlite = dummy

from storm.variables import Variable, RawStrVariable
from storm.database import Database, Connection, Result
from storm.exceptions import install_exceptions, DatabaseModuleError
from storm.expr import (
    Insert, Select, SELECT, Undef, SQLRaw, Union, Except, Intersect,
    compile, compile_insert, compile_select)


install_exceptions(sqlite)


compile = compile.create_child()

@compile.when(Select)
def compile_select_sqlite(compile, select, state):
    if select.offset is not Undef and select.limit is Undef:
        select.limit = sys.maxint
    statement = compile_select(compile, select, state)
    if state.context is SELECT:
        # SQLite breaks with (SELECT ...) UNION (SELECT ...), so we
        # do SELECT * FROM (SELECT ...) instead.  This is important
        # because SELECT ... UNION SELECT ... ORDER BY binds the ORDER BY
        # to the UNION instead of SELECT.
        return "SELECT * FROM (%s)" % statement
예제 #2
0
from storm.databases import dummy

try:
    import MySQLdb
    import MySQLdb.converters
except ImportError:
    MySQLdb = dummy

from storm.expr import (compile, Select, compile_select, Undef, And, Eq,
                        SQLRaw, SQLToken, is_safe_token)
from storm.database import Database, Connection, Result
from storm.exceptions import install_exceptions, DatabaseModuleError


install_exceptions(MySQLdb)


compile = compile.create_child()

@compile.when(Select)
def compile_select_mysql(compile, select, state):
    if select.offset is not Undef and select.limit is Undef:
        select.limit = sys.maxint
    return compile_select(compile, select, state)

@compile.when(SQLToken)
def compile_sql_token_mysql(compile, expr, state):
    """MySQL uses ` as the escape character by default."""
    if is_safe_token(expr) and not compile.is_reserved_word(expr):
        return expr
예제 #3
0
                             LazyValue, DateTimeVariable, DateVariable,
                             TimeVariable, TimeDeltaVariable, BoolVariable,
                             IntVariable, FloatVariable, DecimalVariable,
                             PickleVariable)
from storm.database import Database, Connection, Result, convert_param_marks
from storm.exceptions import install_exceptions, ClosedError, DatabaseModuleError, DatabaseError, DisconnectionError
from storm.info import get_cls_info, ClassAlias
from storm.expr import (Undef, Expr, SetExpr, Select, Insert, Alias, And, Eq,
                        FuncExpr, SQLRaw, Lt, Le, Gt, Ge, Max, Column,
                        is_safe_token, EXPR, Except, Sequence, Like, SQLToken,
                        COLUMN, COLUMN_NAME, COLUMN_PREFIX, TABLE, compile,
                        compile_select, compile_insert, compile_set_expr,
                        compile_like, compile_sql_token, JoinExpr,
                        compile_python, Mod, In)

install_exceptions(oracle)
compile = compile.create_child()

#__db_encoding = 'cp1256'
__default_NLS_LANG = 'AMERICAN_AMERICA.AR8MSWIN1256'

#def set_encoding(db_encoding):
#	global __db_encoding
#	__db_encoding = db_encoding
#
#def db_encoding_to_utf8(text):
#	global __db_encoding
#	if __db_encoding is not None and __db_encoding <> 'utf-8':
#		return text.decode(__db_encoding).encode('utf-8')
#	return text
#
예제 #4
0
except ImportError:
    try:
        from sqlite3 import dbapi2 as sqlite
    except ImportError:
        sqlite = dummy

from storm.compat import bstr, ustr
from storm.variables import Variable, RawStrVariable
from storm.database import Database, Connection, Result
from storm.exceptions import install_exceptions, DatabaseModuleError
from storm.expr import (
    Insert, Select, SELECT, Undef, SQLRaw, Union, Except, Intersect,
    compile, compile_insert, compile_select)


install_exceptions(sqlite)


compile = compile.create_child()

@compile.when(Select)
def compile_select_sqlite(compile, select, state):
    if select.offset is not Undef and select.limit is Undef:
        if sys.maxsize > 2**32:
            # On 64-bit platforms sqlite doesn't like maxint as LIMIT. See also
            # https://lists.ubuntu.com/archives/storm/2013-June/001492.html
            select.limit = sys.maxsize - 1
        else:
            select.limit = sys.maxsize
    statement = compile_select(compile, select, state)
    if state.context is SELECT:
예제 #5
0
    psycopg2 = dummy

from storm.expr import (
    Undef, Expr, SetExpr, Select, Insert, Alias, And, Eq, FuncExpr, SQLRaw,
    Sequence, Like, SQLToken, COLUMN, COLUMN_NAME, COLUMN_PREFIX, TABLE,
    compile, compile_select, compile_insert, compile_set_expr, compile_like,
    compile_sql_token)
from storm.variables import Variable, ListVariable
from storm.database import Database, Connection, Result
from storm.exceptions import (
    install_exceptions, DatabaseError, DatabaseModuleError, InterfaceError,
    OperationalError, ProgrammingError, TimeoutError)
from storm.tracer import TimeoutTracer


install_exceptions(psycopg2)
compile = compile.create_child()


class Returning(Expr):
    """Appends the "RETURNING <primary_columns>" suffix to an INSERT.

    This is only supported in PostgreSQL 8.2+.
    """

    def __init__(self, insert):
        self.insert = insert

@compile.when(Returning)
def compile_returning(compile, expr, state):
    state.push("context", COLUMN)
예제 #6
0
from storm.databases import dummy

try:
    import psycopg2
    import psycopg2.extensions
except:
    psycopg2 = dummy

from storm.expr import (Undef, SetExpr, Insert, Select, Alias, And, Eq,
                        FuncExpr, SQLRaw, Sequence, COLUMN_NAME, compile,
                        compile_insert, compile_select, compile_set_expr)
from storm.variables import Variable, ListVariable
from storm.database import Database, Connection, Result
from storm.exceptions import install_exceptions, DatabaseModuleError

install_exceptions(psycopg2)
compile = compile.create_child()


class currval(FuncExpr):

    name = "currval"

    def __init__(self, column):
        self.column = column


@compile.when(currval)
def compile_currval(compile, expr, state):
    return "currval('%s_%s_seq')" % (compile(expr.column.table,
                                             state), expr.column.name)
예제 #7
0
    import MySQLdb
    import MySQLdb.converters
except ImportError:
    MySQLdb = dummy

from storm.expr import (
    compile, Insert, Select, compile_select, Undef, And, Eq,
    SQLRaw, SQLToken, is_safe_token)
from storm.variables import Variable
from storm.database import Database, Connection, Result
from storm.exceptions import (
    install_exceptions, DatabaseModuleError, OperationalError)
from storm.variables import IntVariable


install_exceptions(MySQLdb)


compile = compile.create_child()

@compile.when(Select)
def compile_select_mysql(compile, select, state):
    if select.offset is not Undef and select.limit is Undef:
        select.limit = sys.maxint
    return compile_select(compile, select, state)

@compile.when(SQLToken)
def compile_sql_token_mysql(compile, expr, state):
    """MySQL uses ` as the escape character by default."""
    if is_safe_token(expr) and not compile.is_reserved_word(expr):
        return expr