bugged
stringlengths
4
228k
fixed
stringlengths
0
96.3M
__index_level_0__
int64
0
481k
def __new__(cls, className, bases, d):
def __new__(cls, className, bases, d):
37,900
def __new__(cls, className, bases, d):
def __new__(cls, className, bases, d):
37,901
def get(cls, id, connection=None, selectResults=None):
def get(cls, id, connection=None, selectResults=None):
37,902
def addColumn(cls, columnDef, changeSchema=False): column = columnDef.withClass(cls) name = column.name assert name != 'id', "The 'id' column is implicit, and should not be defined as a column" cls._SO_columnDict[name] = column cls._SO_columns.append(column)
def addColumn(cls, columnDef, changeSchema=False): column = columnDef.withClass(cls) name = column.name assert name != 'id', "The 'id' column is implicit, and should not be defined as a column" cls._SO_columnDict[name] = column cls._SO_columns.append(column)
37,903
def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return
def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return
37,904
def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return
def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return
37,905
def _SO_finishCreate(self, id=None): # Here's where an INSERT is finalized. # These are all the column values that were supposed # to be set, but were delayed until now: setters = self._SO_createValues.items() # Here's their database names: names = [self._SO_columnDict[v[0]].dbName for v in setters] values = [v[1] for ...
def _SO_finishCreate(self, id=None): # Here's where an INSERT is finalized. # These are all the column values that were supposed # to be set, but were delayed until now: setters = self._SO_createValues.items() # Here's their database names: names = [self._SO_columnDict[v[0]].dbName for v in setters] values = [v[1] for ...
37,906
def getID(obj): if isinstance(obj, SQLObject): return obj.id elif type(obj) is type(1): return obj elif type(obj) is type(1L): return int(obj) elif type(obj) is type(""): return int(obj) elif obj is None: return None
def getID(obj): if isinstance(obj, SQLObject): return obj.id elif type(obj) is type(1): return obj elif type(obj) is type(1L): try: return int(obj) except ValueError: return obj elif type(obj) is type(""): try: return int(obj) except ValueError: return obj elif obj is None: return None
37,907
def __init__(self, dsn=None, host=None, port=None, db=None, user=None, passwd=None, usePygresql=False, **kw): global psycopg, pgdb if usePygresql: if pgdb is None: import pgdb self.module = pgdb else: if psycopg is None: import psycopg self.module = psycopg
def__init__(self,dsn=None,host=None,port=None,db=None,user=None,passwd=None,usePygresql=False,**kw):globalpsycopg,pgdbifusePygresql:ifpgdbisNone:importpgdbself.module=pgdbelse:ifpsycopgisNone:importpsycopgself.module=psycopg
37,908
def makeConnection(self): try: conn = self.module.connect(self.dsn) except self.module.OperationalError, e: raise self.module.OperationalError("%s; used connection string %r" % (e, self.dsn)) if self.autoCommit: # psycopg2 does not have an autocommit method. if hasattr(conn, 'autocommit'): conn.autocommit(1) return con...
def makeConnection(self): try: if self.use_dsn: conn = self.module.connect(self.dsn) else: conn = self.module.connect(**self.dsn_dict) except self.module.OperationalError, e: raise self.module.OperationalError("%s; used connection string %r" % (e, self.dsn)) if self.autoCommit: # psycopg2 does not have an autocommit me...
37,909
def from_python(self, value, state): if value is None: return None if isinstance(value, float): value = str(value) if isinstance(value, (str, unicode)): connection = state.soObject._connection if hasattr(connection, "decimalSeparator"): value = value.replace(connection.decimalSeparator, ".") try: return Decimal(value) ...
def from_python(self, value, state): if value is None: return None if isinstance(value, float): value = str(value) if isinstance(value, (str, unicode)): connection = state.soObject._connection if hasattr(connection, "decimalSeparator"): value = value.replace(connection.decimalSeparator, ".") try: return Decimal(value) ...
37,910
def queryForSelect(self, select): ops = select.ops cls = select.sourceClass if ops.get('distinct', False): q = 'SELECT DISTINCT ' else: q = 'SELECT ' if ops.get('lazyColumns', 0): q += "%s.%s FROM %s WHERE " % \ (cls._table, cls._idName, ", ".join(select.tables)) else: q += "%s.%s, %s FROM %s WHERE " % \ (cls._table, c...
def queryForSelect(self, select): ops = select.ops cls = select.sourceClass if ops.get('distinct', False): q = 'SELECT DISTINCT ' else: q = 'SELECT ' if ops.get('lazyColumns', 0): q += "%s.%s FROM %s WHERE " % \ (cls._table, cls._idName, ", ".join(select.tables)) else: q += "%s.%s, %s FROM %s WHERE " % \ (cls._table, c...
37,911
def coerceID(cls, value): if isinstance(value, cls): return value.id else: return self._idType(value)
def coerceID(cls, value): if isinstance(value, cls): return value.id else: return self._idType(value)
37,912
def BoolConverter(value, db): if db in ('postgres',): if value: return "'t'" else: return "'f'" else: if value: return '1' else: return '0'
def BoolConverter(value, db): if db in ('postgres',): if value: return "'t'" else: return "'f'" else: if value: return '1' else: return '0'
37,913
def cmper(a, b, attr=orderBy): return cmp(getattr(b, attr), getattr(a, attr))
def cmper(a, b, attr=orderBy): return cmp(getattr(b, attr), getattr(a, attr))
37,914
def cmper(a, b, attr=orderBy): return cmp(getattr(a, attr), getattr(b, attr))
def cmper(a, b, attr=orderBy): return cmp(getattr(a, attr), getattr(b, attr))
37,915
def createSQL(self, soClass): tableCreateSQLs = getattr(soClass.sqlmeta, 'createSQL', None) if tableCreateSQLs: assert isinstance(tableCreateSQLs,(str,list,dict,tuple)), ( '%s.sqlmeta.createSQL must be a str, list, dict or tuple.' % (soClass.__name__)) if isinstance(tableCreateSQLs, dict): tableCreateSQLs = tableCreate...
def createSQL(self, soClass): tableCreateSQLs = getattr(soClass.sqlmeta, 'createSQL', None) if tableCreateSQLs: assert isinstance(tableCreateSQLs,(str,list,dict,tuple)), ( '%s.sqlmeta.createSQL must be a str, list, dict or tuple.' % (soClass.__name__)) if isinstance(tableCreateSQLs, dict): tableCreateSQLs = tableCreate...
37,916
def set(self, **kw): if not self.sqlmeta._creating: self.sqlmeta.send(events.RowUpdateSignal, self, kw) # set() is used to update multiple values at once, # potentially with one SQL statement if possible.
def set(self, **kw): if not self.sqlmeta._creating: self.sqlmeta.send(events.RowUpdateSignal, self, kw) # set() is used to update multiple values at once, # potentially with one SQL statement if possible.
37,917
def _validateReturn(self, fieldDict, state): ccType = string.lower(string.strip(fieldDict[self._ccTypeField])) number = string.strip(fieldDict[self._ccNumberField]) number = string.replace(number, ' ', '') number = string.replace(number, '-', '') try: long(number) except ValueError: return {self._ccNumberField: self.me...
def _validateReturn(self, fieldDict, state): ccType = string.lower(string.strip(fieldDict[self._ccTypeField])) number = string.strip(fieldDict[self._ccNumberField]) number = string.replace(number, ' ', '') number = string.replace(number, '-', '') try: long(number) except ValueError: return {self._ccNumberField: self.me...
37,918
def _validateReturn(self, fieldDict, state): ccType = string.lower(string.strip(fieldDict[self._ccTypeField])) number = string.strip(fieldDict[self._ccNumberField]) number = string.replace(number, ' ', '') number = string.replace(number, '-', '') try: long(number) except ValueError: return {self._ccNumberField: self.me...
def _validateReturn(self, fieldDict, state): ccType = string.lower(string.strip(fieldDict[self._ccTypeField])) number = string.strip(fieldDict[self._ccNumberField]) number = string.replace(number, ' ', '') number = string.replace(number, '-', '') try: long(number) except ValueError: return {self._ccNumberField: self.me...
37,919
def __init__(self, db, user, password='', host='localhost', autoCommit=0, **kw): global sqlmodule if not sqlmodule: try: import adodbapi as sqlmodule self.dbconnection = sqlmodule.connect # ADO uses unicode only (AFAIK) self.usingUnicodeStrings = True # MSDE does not allow SQL server login if "sspi" in kw and kw["sspi"...
def __init__(self, db, user, password='', host='localhost', autoCommit=0, **kw): global sqlmodule if not sqlmodule: try: import adodbapi as sqlmodule self.dbconnection = sqlmodule.connect # ADO uses unicode only (AFAIK) self.usingUnicodeStrings = True # MSDE does not allow SQL server login if kw.get("sspi"): conn_str +...
37,920
def __init__(self, db, user, password='', host='localhost', autoCommit=0, **kw): global sqlmodule if not sqlmodule: try: import adodbapi as sqlmodule self.dbconnection = sqlmodule.connect # ADO uses unicode only (AFAIK) self.usingUnicodeStrings = True # MSDE does not allow SQL server login if "sspi" in kw and kw["sspi"...
def __init__(self, db, user, password='', host='localhost', autoCommit=0, **kw): global sqlmodule if not sqlmodule: try: import adodbapi as sqlmodule self.dbconnection = sqlmodule.connect # ADO uses unicode only (AFAIK) self.usingUnicodeStrings = True # MSDE does not allow SQL server login if "sspi" in kw and kw["sspi"...
37,921
def __classinit__(cls, new_attrs):
def __classinit__(cls, new_attrs):
37,922
def _create(self, id, **kw):
def _create(self, id, **kw):
37,923
def connectionFromURI(cls, uri): user, password, host, port, path, args = cls._parseURI(uri) return cls(db=path.strip('/'), user=user or '', passwd=password or '', host=host or 'localhost', port=port or '', **args)
def connectionFromURI(cls, uri): user, password, host, port, path, args = cls._parseURI(uri) return cls(db=path.strip('/'), user=user or '', passwd=password or '', host=host or 'localhost', port=port or '', **args)
37,924
def __classinit__(cls, new_attrs):
def __classinit__(cls, new_attrs):
37,925
def best_upgrade(self, current, dest, target_dbname): current_dir = os.path.join(self.base_dir(), current) if self.options.verbose > 1: print ('Looking in %s for upgraders' % self.shorten_filename(current_dir)) upgraders = [] for fn in os.listdir(current_dir): match = self.upgrade_regex.search(fn) if not match: if self...
def best_upgrade(self, current, dest, target_dbname): current_dir = os.path.join(self.base_dir(), current) if self.options.verbose > 1: print ('Looking in %s for upgraders' % self.shorten_filename(current_dir)) upgraders = [] for fn in os.listdir(current_dir): match = self.upgrade_regex.search(fn) if not match: if self...
37,926
def __init__(self, filename, autoCommit=1, **kw): global sqlite if sqlite is None: import sqlite self.module = sqlite self.filename = filename # full path to sqlite-db-file if not autoCommit and not kw.has_key('pool'): # Pooling doesn't work with transactions... kw['pool'] = 0 # use only one connection for sqlite - su...
def __init__(self, filename, autoCommit=1, **kw): global sqlite if sqlite is None: import sqlite self.module = sqlite self.filename = filename # full path to sqlite-db-file if not autoCommit and not kw.has_key('pool'): # Pooling doesn't work with transactions... kw['pool'] = 0 # use only one connection for sqlite - su...
37,927
def __new__(cls, className, bases, d):
def __new__(cls, className, bases, d):
37,928
def get(cls, id, connection=None, selectResults=None, childResults=None, childUpdate=False):
def get(cls, id, connection=None, selectResults=None, childResults=None, childUpdate=False):
37,929
def _queryInsertID(self, conn, soInstance, id, names, values): """Firebird uses 'generators' to create new ids for a table. The users needs to create a generator named GEN_<tablename> for each table this method to work.""" table = soInstance.sqlmeta.table idName = soInstance.sqlmeta.idName sequenceName = getattr(soInst...
def _queryInsertID(self, conn, soInstance, id, names, values): """Firebird uses 'generators' to create new ids for a table. The users needs to create a generator named GEN_<tablename> for each table this method to work.""" table = soInstance.sqlmeta.table idName = soInstance.sqlmeta.idName sequenceName = getattr(soInst...
37,930
def _queryInsertID(self, conn, soInstance, id, names, values): """Firebird uses 'generators' to create new ids for a table. The users needs to create a generator named GEN_<tablename> for each table this method to work.""" table = soInstance.sqlmeta.table idName = soInstance.sqlmeta.idName sequenceName = getattr(soInst...
def _queryInsertID(self, conn, soInstance, id, names, values): """Firebird uses 'generators' to create new ids for a table. The users needs to create a generator named GEN_<tablename> for each table this method to work.""" table = soInstance.sqlmeta.table idName = soInstance.sqlmeta.idName sequenceName = getattr(soInst...
37,931
def _queryInsertID(self, conn, soInstance, id, names, values): """Firebird uses 'generators' to create new ids for a table. The users needs to create a generator named GEN_<tablename> for each table this method to work.""" table = soInstance.sqlmeta.table idName = soInstance.sqlmeta.idName sequenceName = getattr(soInst...
def _queryInsertID(self, conn, soInstance, id, names, values): """Firebird uses 'generators' to create new ids for a table. The users needs to create a generator named GEN_<tablename> for each table this method to work.""" table = soInstance.sqlmeta.table idName = soInstance.sqlmeta.idName sequenceName = getattr(soInst...
37,932
def columnsFromSchema(self, tableName, soClass): colData = self.queryAll("SHOW COLUMNS FROM %s" % tableName) results = [] for field, t, nullAllowed, key, default, extra in colData: if field == 'id': continue colClass, kw = self.guessClass(t) if self.kw['use_unicode'] and colClass is col.StringCol: colClass = col.Unicod...
def columnsFromSchema(self, tableName, soClass): colData = self.queryAll("SHOW COLUMNS FROM %s" % tableName) results = [] for field, t, nullAllowed, key, default, extra in colData: if field == 'id': continue colClass, kw = self.guessClass(t) if self.kw.get('use_unicode') and colClass is col.StringCol: colClass = col.Un...
37,933
def createTableSQL(cls, createJoinTables=True, createIndexes=True, connection=None): conn = connection or cls._connection sql, constraints = conn.createTableSQL(cls) if createJoinTables: join_sql = cls.createJoinTablesSQL(connection=conn) if join_sql: sql = ';\n' + join_sql if createIndexes: index_sql = cls.createIndex...
def createTableSQL(cls, createJoinTables=True, createIndexes=True, connection=None): conn = connection or cls._connection sql, constraints = conn.createTableSQL(cls) if createJoinTables: join_sql = cls.createJoinTablesSQL(connection=conn) if join_sql: sql += ';\n' + join_sql if createIndexes: index_sql = cls.createInde...
37,934
def clear(self): self.cache.clear() self.expiredCache.clear()
def clear(self): if self.doCache: self.cache.clear() self.expiredCache.clear()
37,935
def performJoin(self, inst): results = self.otherClass.select(getattr(self.otherClass.q, self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn)) == inst.id) if self.orderBy is NoDefault: self.orderBy = self.otherClass.sqlmeta.defaultOrder return results.orderBy(self.orderBy)
def performJoin(self, inst): if inst.sqlmeta._perConnection: conn = inst._connection else: conn = None results = self.otherClass.select(getattr(self.otherClass.q, self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn)) == inst.id, connection=conn) if self.orderBy is NoDefault: self.orderBy = self.otherClass.s...
37,936
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
37,937
def guessClass(self, t): if t.count('int'): return col.IntCol, {} elif t.count('varying'): if '(' in t: return col.StringCol, {'length': int(t[t.index('(')+1:-1])} else: # varchar without length in Postgres means any length return col.StringCol, {} elif t.startswith('character('): return col.StringCol, {'length': int(t...
def guessClass(self, t): if t.count('int'): return col.IntCol, {} elif t.count('varying') or t.count('varchar'): if '(' in t: return col.StringCol, {'length': int(t[t.index('(')+1:-1])} else: # varchar without length in Postgres means any length return col.StringCol, {} elif t.startswith('character('): return col.Strin...
37,938
def to_python(self, value, state): if value is None: return None if isinstance(value, (datetime.datetime, datetime.date, datetime.time, sqlbuilder.SQLExpression)): return value if mxdatetime_available: if isinstance(value, DateTimeType): # convert mxDateTime instance to datetime if (self.format.find("%H") >= 0) or (sel...
def to_python(self, value, state): if value is None: return None if isinstance(value, (datetime.datetime, datetime.date, datetime.time, sqlbuilder.SQLExpression)): return value if mxdatetime_available: if isinstance(value, DateTimeType): # convert mxDateTime instance to datetime if (self.format.find("%H") >= 0) or (sel...
37,939
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
37,940
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
37,941
def __getattr__(self, attr): # @@: This passes through private variable access too... should it? # Also magic methods, like __str__ return getattr(self, select, attr)
def __getattr__(self, attr): # @@: This passes through private variable access too... should it? # Also magic methods, like __str__ return getattr(self, select, attr)
37,942
def __init__(self, sourceClass, clause, clauseTables=None, **ops): self.sourceClass = sourceClass if clause is None or isinstance(clause, str) and clause == 'all': clause = sqlbuilder.SQLTrueClause self.clause = clause tablesDict = sqlbuilder.tablesUsedDict(self.clause) tablesDict[sourceClass._table] = 1 if clauseTable...
def __init__(self, sourceClass, clause, clauseTables=None, **ops): self.sourceClass = sourceClass if clause is None or isinstance(clause, str) and clause == 'all': clause = sqlbuilder.SQLTrueClause self.clause = clause tablesDict = sqlbuilder.tablesUsedDict(self.clause) tablesDict[sourceClass._table] = 1 if clauseTable...
37,943
def __init__(self, otherClass=None, **kw): kw['otherClass'] = otherClass kw['joinDef'] = self self.kw = kw if self.kw.has_key('joinMethodName'): self._joinMethodName = self.kw.pop('joinMethodName') else: self._joinMethodName = None
def __init__(self, otherClass=None, **kw): kw['otherClass'] = otherClass kw['joinDef'] = self self.kw = kw if self.kw.has_key('joinMethodName'): self._joinMethodName = popKey(self.kw, 'joinMethodName') else: self._joinMethodName = None
37,944
def makeConnection(self): con = self.dbconnection( *self.make_conn_str(self) ) cur = con.cursor() cur.execute('SET ANSI_NULLS ON') cur.execute("SELECT CAST('12345.21' AS DECIMAL(10, 2))") self.decimalSeparator = cur.fetchone()[0][-3] cur.close() return con
def makeConnection(self): con = self.dbconnection( *self.make_conn_str(self) ) cur = con.cursor() cur.execute('SET ANSI_NULLS ON') cur.execute("SELECT CAST('12345.21' AS DECIMAL(10, 2))") self.decimalSeparator = str(cur.fetchone()[0])[-3] cur.close() return con
37,945
def StringLikeConverter(value, db): if isinstance(value, array.array): try: value = value.tounicode() except ValueError: value = value.tostring() if db in ('mysql', 'postgres'): for orig, repl in sqlStringReplace: value = value.replace(orig, repl) elif db in ('sqlite', 'firebird', 'sybase', 'maxdb'): value = value.rep...
def StringLikeConverter(value, db): if isinstance(value, array_type): try: value = value.tounicode() except ValueError: value = value.tostring() if db in ('mysql', 'postgres'): for orig, repl in sqlStringReplace: value = value.replace(orig, repl) elif db in ('sqlite', 'firebird', 'sybase', 'maxdb'): value = value.repl...
37,946
def StringLikeConverter(value, db): if isinstance(value, array.array): try: value = value.tounicode() except ValueError: value = value.tostring() if db in ('mysql', 'postgres'): for orig, repl in sqlStringReplace: value = value.replace(orig, repl) elif db in ('sqlite', 'firebird', 'sybase', 'maxdb'): value = value.rep...
def StringLikeConverter(value, db): if isinstance(value, array.array): try: value = value.tounicode() except ValueError: value = value.tostring() if db in ('mysql', 'postgres'): for orig, repl in sqlStringReplace: value = value.replace(orig, repl) elif db in ('sqlite', 'firebird', 'sybase', 'maxdb'): value = value.rep...
37,947
def __init__(self, dsn=None, host=None, port=None, db=None, user=None, passwd=None, usePygresql=False, **kw): global psycopg, pgdb self.usePygresql = usePygresql if usePygresql: if pgdb is None: import pgdb self.module = pgdb else: if psycopg is None: import psycopg self.module = psycopg
def __init__(self, dsn=None, host=None, port=None, db=None, user=None, passwd=None, usePygresql=False, **kw): global psycopg, pgdb self.usePygresql = usePygresql if usePygresql: if pgdb is None: import pgdb self.module = pgdb else: if psycopg is None: import psycopg self.module = psycopg
37,948
def _queryInsertID(self, conn, soInstance, id, names, values): table = soInstance.sqlmeta.table idName = soInstance.sqlmeta.idName c = conn.cursor() if id is not None: names = [idName] + names values = [id] + values q = self._insertSQL(table, names, values) if self.debug: self.printDebug(conn, q, 'QueryIns') self._exec...
def _queryInsertID(self, conn, soInstance, id, names, values): table = soInstance.sqlmeta.table idName = soInstance.sqlmeta.idName c = conn.cursor() if id is not None: names = [idName] + names values = [id] + values q = self._insertSQL(table, names, values) if self.debug: self.printDebug(conn, q, 'QueryIns') self._exec...
37,949
def test_dynamicJoin(self): if not supports('dynamicColumn'): return col = KeyCol('personID', foreignKey='Person') Phone.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] e...
def test_dynamicJoin(self): if not supports('dynamicColumn'): return col = KeyCol('personID', foreignKey='Person') Phone.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] e...
37,950
def get(cls, id, connection=None, selectResults=None, childResults=None, childUpdate=False):
def get(cls, id, connection=None, selectResults=None, childResults=None, childUpdate=False):
37,951
def get(cls, id, connection=None, selectResults=None, childResults=None, childUpdate=False):
def get(cls, id, connection=None, selectResults=None, childResults=None, childUpdate=False):
37,952
def addColumn(cls, columnDef, changeSchema=False, connection=None, childUpdate=False): #DSM: Try to add parent properties to the current class #DSM: Only do this once if possible at object creation and once for #DSM: each new dynamic column to refresh the current class if childUpdate or cls._parentClass: for col in cls...
def addColumn(cls, columnDef, changeSchema=False, connection=None, childUpdate=False): #DSM: Try to add parent properties to the current class #DSM: Only do this once if possible at object creation and once for #DSM: each new dynamic column to refresh the current class if childUpdate or cls._parentClass: for col in cls...
37,953
def guessClass(self, t): if t.count('int'): return col.IntCol, {} elif t.count('varying'): return col.StringCol, {'length': int(t[t.index('(')+1:-1])} elif t.startswith('character('): return col.StringCol, {'length': int(t[t.index('(')+1:-1]), 'varchar': False} elif t == 'text': return col.StringCol, {} elif t.startswi...
def guessClass(self, t): if t.count('int'): return col.IntCol, {} elif t.count('varying'): if '(' in t: return col.StringCol, {'length': int(t[t.index('(')+1:-1])} else: return col.StringCol, {} elif t.startswith('character('): return col.StringCol, {'length': int(t[t.index('(')+1:-1]), 'varchar': False} elif t == 'tex...
37,954
def getConnection(self): # SQLite can't share connections between threads, and so can't # pool connections. Since we are isolating threads here, we # don't have to worry about locking as much. if self._memory: return self.makeConnection() threadid = thread.get_ident() if (self._pool is not None and self._threadPool.ha...
def getConnection(self): # SQLite can't share connections between threads, and so can't # pool connections. Since we are isolating threads here, we # don't have to worry about locking as much. if self._memory: conn = self.makeConnection() self._connectionNumbers[id(conn)] = self._connectionCount self._connectionCount ...
37,955
def _set_position(self, value): self.employee.position = value
def _set_position(self, value): self.employee.position = value
37,956
def _set_longitude(self, value): self._so.longitude = value
def _set_longitude(self, value): self._so.longitude = value
37,957
def getID(obj): try: return obj.id except AttributeError: return int(id)
def getID(obj): try: return obj.id except AttributeError: return int(obj)
37,958
def __init__(self, filename, autoCommit=1, **kw): global sqlite global using_sqlite2 if sqlite is None: try: from pysqlite2 import dbapi2 as sqlite using_sqlite2 = True except ImportError: import sqlite using_sqlite2 = False self.module = sqlite self.filename = filename # full path to sqlite-db-file self._memory = fil...
def __init__(self, filename, autoCommit=1, **kw): global sqlite global using_sqlite2 if sqlite is None: try: from pysqlite2 import dbapi2 as sqlite using_sqlite2 = True except ImportError: import sqlite using_sqlite2 = False self.module = sqlite self.filename = filename # full path to sqlite-db-file self._memory = fil...
37,959
for jdef in soClass._parentClass.sqlmeta.joins: join = jdef.withClass(soClass) jname = join.joinMethodName jarn = join.addRemoveName setattr(soClass, getterName(jname), eval('lambda self: self._parent.%s' % jname)) if hasattr(join, 'remove'): setattr(soClass, 'remove' + jarn, eval('lambda self,o: self._parent.remove%s...
for join in soClass._parentClass.sqlmeta.joins: jname = join.joinMethodName jarn = join.addRemoveName setattr(soClass, getterName(jname), eval('lambda self: self._parent.%s' % jname)) if hasattr(join, 'remove'): setattr(soClass, 'remove' + jarn, eval('lambda self,o: self._parent.remove%s(o)' % jarn)) if hasattr(join, ...
37,960
def __init__(self, db, user, password='', host='localhost', autoCommit=0, **kw): global sqlmodule if not sqlmodule: try: import adodbapi as sqlmodule self.dbconnection = sqlmodule.connect # ADO uses unicode only (AFAIK) self.usingUnicodeStrings = True
def __init__(self, db, user, password='', host='localhost', autoCommit=0, **kw): global sqlmodule if not sqlmodule: try: import adodbapi as sqlmodule self.dbconnection = sqlmodule.connect # ADO uses unicode only (AFAIK) self.usingUnicodeStrings = True
37,961
def __init__(self, db, user, password='', host='localhost', autoCommit=0, **kw): global sqlmodule if not sqlmodule: try: import adodbapi as sqlmodule self.dbconnection = sqlmodule.connect # ADO uses unicode only (AFAIK) self.usingUnicodeStrings = True
def __init__(self, db, user, password='', host='localhost', autoCommit=0, **kw): global sqlmodule if not sqlmodule: try: import adodbapi as sqlmodule self.dbconnection = sqlmodule.connect # ADO uses unicode only (AFAIK) self.usingUnicodeStrings = True
37,962
def _toPython(self, value, state=None): return self.attemptConvert(self, value, state, toPython)
def _toPython(self, value, state=None): return self.attemptConvert(self, value, state, toPython)
37,963
def _parseURI(uri): schema, rest = uri.split(':', 1) assert rest.startswith('/'), "URIs must start with scheme:/ -- you did not include a / (in %r)" % rest if rest.startswith('/') and not rest.startswith('//'): host = None rest = rest[1:] elif rest.startswith('///'): host = None rest = rest[3:] else: rest = rest[2:] if...
def _parseURI(uri): schema, rest = uri.split(':', 1) assert rest.startswith('/'), "URIs must start with scheme:/ -- you did not include a / (in %r)" % rest if rest.startswith('/') and not rest.startswith('//'): host = None rest = rest[1:] elif rest.startswith('///'): host = None rest = rest[3:] else: rest = rest[2:] if...
37,964
def performJoin(self, inst): pythonColumn = self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn) results = self.otherClass.select(getattr(self.otherClass.q, pythonColumn) == inst.id) if results.count() == 0: if not self.makeDefault: return None else: kw = {pythonColumn[:-2]: inst} # skipping the ID (from fo...
def performJoin(self, inst): pythonColumn = self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn) results = self.otherClass.select( getattr(self.otherClass.q, pythonColumn) == inst.id, connection=conn ) if results.count() == 0: if not self.makeDefault: return None else: kw = {pythonColumn[:-2]: inst} # skipp...
37,965
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
37,966
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
def performJoin(self, inst): options={ 'otherTable' : self.otherClass.sqlmeta.table, 'otherID' : self.otherClass.sqlmeta.idName, 'interTable' : self.intermediateTable, 'table' : self.soClass.sqlmeta.table, 'ID' : self.soClass.sqlmeta.idName, 'joinCol' : self.joinColumn, 'otherCol' : self.otherColumn, 'idValue' : inst.i...
37,967
def __init__(self, dsn=None, host=None, db=None, user=None, passwd=None, autoCommit=1, usePygresql=False, **kw): global psycopg, pgdb if usePygresql: if pgdb is None: import pgdb self.pgmodule = pgdb else: if psycopg is None: import psycopg self.pgmodule = psycopg
def __init__(self, dsn=None, host=None, db=None, user=None, passwd=None, autoCommit=1, usePygresql=False, **kw): global psycopg, pgdb if usePygresql: if pgdb is None: import pgdb self.pgmodule = pgdb else: if psycopg is None: import psycopg self.pgmodule = psycopg
37,968
def __getattr__(self, attr): # @@: This passes through private variable access too... should it? # Also magic methods, like __str__ return getattr(self, select, attr)
def __getattr__(self, attr): # @@: This passes through private variable access too... should it? # Also magic methods, like __str__ return getattr(self, select, attr)
37,969
def addColumn(cls, columnDef, changeSchema=False): column = columnDef.withClass(cls) name = column.name assert name != 'id', "The 'id' column is implicit, and should not be defined as a column" cls._SO_columnDict[name] = column cls._SO_columns.append(column)
def addColumn(cls, columnDef, changeSchema=False, connection=None): column = columnDef.withClass(cls) name = column.name assert name != 'id', "The 'id' column is implicit, and should not be defined as a column" cls._SO_columnDict[name] = column cls._SO_columns.append(column)
37,970
def addColumn(cls, columnDef, changeSchema=False): column = columnDef.withClass(cls) name = column.name assert name != 'id', "The 'id' column is implicit, and should not be defined as a column" cls._SO_columnDict[name] = column cls._SO_columns.append(column)
def addColumn(cls, columnDef, changeSchema=False): column = columnDef.withClass(cls) name = column.name assert name != 'id', "The 'id' column is implicit, and should not be defined as a column" cls._SO_columnDict[name] = column cls._SO_columns.append(column)
37,971
def addColumnsFromDatabase(cls): for columnDef in cls._connection.columnsFromSchema(cls._table, cls): alreadyExists = False for c in cls._columns: if c.name == columnDef.name: alreadyExists = True break if not alreadyExists: cls.addColumn(columnDef)
def addColumnsFromDatabase(cls, connection=None): conn = connection or cls._connection for columnDef in conn.columnsFromSchema(cls._table, cls): alreadyExists = False for c in cls._columns: if c.name == columnDef.name: alreadyExists = True break if not alreadyExists: cls.addColumn(columnDef)
37,972
def delColumn(cls, column, changeSchema=False): if isinstance(column, str): column = cls._SO_columnDict[column] if isinstance(column, col.Col): for c in cls._SO_columns: if column is c.columnDef: column = c break cls._SO_columns.remove(column) cls._columns.remove(column.columnDef) name = column.name del cls._SO_columnD...
def delColumn(cls, column, changeSchema=False, connection=None): if isinstance(column, str): column = cls._SO_columnDict[column] if isinstance(column, col.Col): for c in cls._SO_columns: if column is c.columnDef: column = c break cls._SO_columns.remove(column) cls._columns.remove(column.columnDef) name = column.name de...
37,973
def delColumn(cls, column, changeSchema=False): if isinstance(column, str): column = cls._SO_columnDict[column] if isinstance(column, col.Col): for c in cls._SO_columns: if column is c.columnDef: column = c break cls._SO_columns.remove(column) cls._columns.remove(column.columnDef) name = column.name del cls._SO_columnD...
def delColumn(cls, column, changeSchema=False): if isinstance(column, str): column = cls._SO_columnDict[column] if isinstance(column, col.Col): for c in cls._SO_columns: if column is c.columnDef: column = c break cls._SO_columns.remove(column) cls._columns.remove(column.columnDef) name = column.name del cls._SO_columnD...
37,974
def selectBy(cls, connection=None, **kw): return SelectResults(cls, cls._connection._SO_columnClause(cls, kw), connection=connection)
def selectBy(cls, connection=None, **kw): return SelectResults(cls, cls._connection._SO_columnClause(cls, kw), connection=connection)
37,975
def selectBy(cls, connection=None, **kw): return SelectResults(cls, cls._connection._SO_columnClause(cls, kw), connection=connection)
def selectBy(cls, connection=None, **kw): return SelectResults(cls, cls._connection._SO_columnClause(cls, kw), connection=connection)
37,976
def dropTable(cls, ifExists=False, dropJoinTables=True, cascade=False): if ifExists and not cls._connection.tableExists(cls._table): return cls._connection.dropTable(cls._table, cascade) if dropJoinTables: cls.dropJoinTables(ifExists=ifExists)
def dropTable(cls, ifExists=False, dropJoinTables=True, cascade=False): if ifExists and not cls._connection.tableExists(cls._table): return conn.dropTable(cls._table, cascade) if dropJoinTables: cls.dropJoinTables(ifExists=ifExists)
37,977
def dropTable(cls, ifExists=False, dropJoinTables=True, cascade=False): if ifExists and not cls._connection.tableExists(cls._table): return cls._connection.dropTable(cls._table, cascade) if dropJoinTables: cls.dropJoinTables(ifExists=ifExists)
def dropTable(cls, ifExists=False, dropJoinTables=True, cascade=False): if ifExists and not cls._connection.tableExists(cls._table): return cls._connection.dropTable(cls._table, cascade) if dropJoinTables: cls.dropJoinTables(ifExists=ifExists)
37,978
def createTable(cls, ifNotExists=False, createJoinTables=True): if ifNotExists and cls._connection.tableExists(cls._table): return cls._connection.createTable(cls) if createJoinTables: cls.createJoinTables(ifNotExists=ifNotExists)
def createTable(cls, ifNotExists=False, createJoinTables=True, connection=None): conn = connection or cls._connection if ifNotExists and conn.tableExists(cls._table): return cls._connection.createTable(cls) if createJoinTables: cls.createJoinTables(ifNotExists=ifNotExists)
37,979
def createTable(cls, ifNotExists=False, createJoinTables=True): if ifNotExists and cls._connection.tableExists(cls._table): return cls._connection.createTable(cls) if createJoinTables: cls.createJoinTables(ifNotExists=ifNotExists)
def createTable(cls, ifNotExists=False, createJoinTables=True): if ifNotExists and cls._connection.tableExists(cls._table): return conn.createTable(cls) if createJoinTables: cls.createJoinTables(ifNotExists=ifNotExists)
37,980
def createTable(cls, ifNotExists=False, createJoinTables=True): if ifNotExists and cls._connection.tableExists(cls._table): return cls._connection.createTable(cls) if createJoinTables: cls.createJoinTables(ifNotExists=ifNotExists)
def createTable(cls, ifNotExists=False, createJoinTables=True): if ifNotExists and cls._connection.tableExists(cls._table): return cls._connection.createTable(cls) if createJoinTables: cls.createJoinTables(ifNotExists=ifNotExists)
37,981
def createTableSQL(cls, createJoinTables=True): sql = cls._connection.createTableSQL(cls) if createJoinTables: sql += '\n' + cls.createJoinTablesSQL() return sql
def createTableSQL(cls, createJoinTables=True, connection=None): conn = connection or cls._connection sql = conn.createTableSQL(cls) if createJoinTables: sql += '\n' + cls.createJoinTablesSQL() return sql
37,982
def createTableSQL(cls, createJoinTables=True): sql = cls._connection.createTableSQL(cls) if createJoinTables: sql += '\n' + cls.createJoinTablesSQL() return sql
def createTableSQL(cls, createJoinTables=True): sql = cls._connection.createTableSQL(cls) if createJoinTables: sql += '\n' + cls.createJoinTablesSQL(connection=conn) return sql
37,983
def createJoinTables(cls, ifNotExists=False): for join in cls._getJoinsToCreate(): if ifNotExists and \ cls._connection.tableExists(join.intermediateTable): continue cls._connection._SO_createJoinTable(join)
def createJoinTables(cls, ifNotExists=False, connection=None): conn = connection or cls._connection for join in cls._getJoinsToCreate(): if ifNotExists and \ cls._connection.tableExists(join.intermediateTable): continue cls._connection._SO_createJoinTable(join)
37,984
def createJoinTables(cls, ifNotExists=False): for join in cls._getJoinsToCreate(): if ifNotExists and \ cls._connection.tableExists(join.intermediateTable): continue cls._connection._SO_createJoinTable(join)
def createJoinTables(cls, ifNotExists=False): for join in cls._getJoinsToCreate(): if ifNotExists and \ conn.tableExists(join.intermediateTable): continue cls._connection._SO_createJoinTable(join)
37,985
def createJoinTables(cls, ifNotExists=False): for join in cls._getJoinsToCreate(): if ifNotExists and \ cls._connection.tableExists(join.intermediateTable): continue cls._connection._SO_createJoinTable(join)
def createJoinTables(cls, ifNotExists=False): for join in cls._getJoinsToCreate(): if ifNotExists and \ cls._connection.tableExists(join.intermediateTable): continue cls._connection._SO_createJoinTable(join)
37,986
def createJoinTablesSQL(cls): sql = [] for join in cls._getJoinsToCreate(): sql.append(cls._connection._SO_createJoinTableSQL(join)) return '\n'.join(sql)
def createJoinTablesSQL(cls, connection=None): conn = connection or cls._connection sql = [] for join in cls._getJoinsToCreate(): sql.append(cls._connection._SO_createJoinTableSQL(join)) return '\n'.join(sql)
37,987
def createJoinTablesSQL(cls): sql = [] for join in cls._getJoinsToCreate(): sql.append(cls._connection._SO_createJoinTableSQL(join)) return '\n'.join(sql)
def createJoinTablesSQL(cls): sql = [] for join in cls._getJoinsToCreate(): sql.append(conn._SO_createJoinTableSQL(join)) return '\n'.join(sql)
37,988
def dropJoinTables(cls, ifExists=False): for join in cls._SO_joinList: if not join: continue if not join.hasIntermediateTable(): continue if join.soClass.__name__ > join.otherClass.__name__: continue if ifExists and \ not cls._connection.tableExists(join.intermediateTable): continue cls._connection._SO_dropJoinTable(jo...
def dropJoinTables(cls, ifExists=False, connection=None): conn = connection or cls._connection for join in cls._SO_joinList: if not join: continue if not join.hasIntermediateTable(): continue if join.soClass.__name__ > join.otherClass.__name__: continue if ifExists and \ not cls._connection.tableExists(join.intermediat...
37,989
def dropJoinTables(cls, ifExists=False): for join in cls._SO_joinList: if not join: continue if not join.hasIntermediateTable(): continue if join.soClass.__name__ > join.otherClass.__name__: continue if ifExists and \ not cls._connection.tableExists(join.intermediateTable): continue cls._connection._SO_dropJoinTable(jo...
def dropJoinTables(cls, ifExists=False): for join in cls._SO_joinList: if not join: continue if not join.hasIntermediateTable(): continue if join.soClass.__name__ > join.otherClass.__name__: continue if ifExists and \ not conn.tableExists(join.intermediateTable): continue cls._connection._SO_dropJoinTable(join)
37,990
def dropJoinTables(cls, ifExists=False): for join in cls._SO_joinList: if not join: continue if not join.hasIntermediateTable(): continue if join.soClass.__name__ > join.otherClass.__name__: continue if ifExists and \ not cls._connection.tableExists(join.intermediateTable): continue cls._connection._SO_dropJoinTable(jo...
def dropJoinTables(cls, ifExists=False): for join in cls._SO_joinList: if not join: continue if not join.hasIntermediateTable(): continue if join.soClass.__name__ > join.otherClass.__name__: continue if ifExists and \ not cls._connection.tableExists(join.intermediateTable): continue cls._connection._SO_dropJoinTable(jo...
37,991
def clearTable(cls): # 3-03 @@: Maybe this should check the cache... but it's # kind of crude anyway, so... cls._connection.clearTable(cls._table)
def clearTable(cls, connection=None): # 3-03 @@: Maybe this should check the cache... but it's # kind of crude anyway, so... cls._connection.clearTable(cls._table)
37,992
def clearTable(cls): # 3-03 @@: Maybe this should check the cache... but it's # kind of crude anyway, so... cls._connection.clearTable(cls._table)
def clearTable(cls): # 3-03 @@: Maybe this should check the cache... but it's # kind of crude anyway, so... cls._connection.clearTable(cls._table)
37,993
def sqlrepr(cls, value): return cls._connection.sqlrepr(value)
def sqlrepr(cls, value): return cls._connection.sqlrepr(value)
37,994
def makeConnection(self): return MySQLdb.connect(host=self.host, port=self.port, db=self.db, user=self.user, passwd=self.password)
def makeConnection(self): return MySQLdb.connect(host=self.host, port=self.port, db=self.db, user=self.user, passwd=self.password)
37,995
def _executeRetry(self, conn, cursor, query): while 1: try: if self.need_unicode: # For MysqlDB 1.2.1 and later, we go # encoding->unicode->charset (in the mysql db) myquery = unicode(query, self.encoding) return cursor.execute(myquery) else: return cursor.execute(query) except MySQLdb.OperationalError, e: if e.args[0]...
def _executeRetry(self, conn, cursor, query): while 1: try: if self.need_unicode: # For MysqlDB 1.2.1 and later, we go # encoding->unicode->charset (in the mysql db) myquery = unicode(query, self.encoding) return cursor.execute(myquery) else: return cursor.execute(query) except MySQLdb.OperationalError, e: if e.args[0]...
37,996
def _get_phoneNumber(self): value = self._SO_get_phoneNumber() number = '(%s) %s-%s' % (value[0:3], value[3:6], value[6:10]) if len(value) > 10: number += ' ext.%s' % value[10:] return number
def _get_phoneNumber(self): value = self._SO_get_phoneNumber() number = '(%s) %s-%s' % (value[0:3], value[3:6], value[6:10]) if len(value) > 10: number += ' ext.%s' % value[10:] return number
37,997
def __repr__(self): return '<%s %i %s>' \ % (self.__class__.__name__, self.id, ' '.join(['%s=%s' % (name, repr(value)) for name, value in self._reprItems()]))
def __repr__(self): return '<%s %r %s>' \ % (self.__class__.__name__, self.id, ' '.join(['%s=%s' % (name, repr(value)) for name, value in self._reprItems()]))
37,998
def _SO_columnClause(self, soClass, kw): ops = {None: "IS"} data = {} if 'id' in kw: data[soClass.sqlmeta.idName] = kw['id'] else: for key, col in soClass.sqlmeta.columns.items(): if key in kw: data[col.dbName] = kw[key] elif col.foreignName in kw: obj = kw[col.foreignName] if obj is None: data[col.dbName] = None else:...
def _SO_columnClause(self, soClass, kw): ops = {None: "IS"} data = {} if 'id' in kw: data[soClass.sqlmeta.idName] = kw['id'] for key, col in soClass.sqlmeta.columns.items(): if key in kw: data[col.dbName] = kw[key] elif col.foreignName in kw: obj = kw[col.foreignName] if obj is None: data[col.dbName] = None else: data[...
37,999