Exemple #1
0
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
    return '`%s`' % expr.replace('`', '``')

Exemple #2
0
                             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
#
#def utf8_to_db_encoding(text):