Changeset 10087:9bc4df280d58 in orange


Ignore:
Timestamp:
02/08/12 00:22:21 (2 years ago)
Author:
Crt Gorup <crt.gorup@…>
Branch:
default
rebase_source:
ebc2b1edce7d4f3c2ede8af3b45e18eb960bc1b6
Message:

Added support for sqlite.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/data/sql.py

    r9993 r10087  
    9494            argTrans["database"] = "db" 
    9595            quirks = __PostgresQuirkFix(dbmod) 
     96            quirks.parameter = "%s" 
    9697        elif schema == 'mysql': 
    9798            import MySQLdb as dbmod 
    9899            quirks = __MySQLQuirkFix(dbmod) 
     100            quirks.parameter = "%s" 
     101        elif schema == "sqlite": 
     102            import sqlite3 as dbmod 
     103            quirks = __PostgresQuirkFix(dbmod) 
     104            quirks.parameter = "?" 
     105            return (quirks, dbmod.connect(host)) 
    99106 
    100107        dbArgDict = {} 
    101  
     108        print host 
    102109        if user: 
    103110            dbArgDict[argTrans['user']] = user 
     
    396403                    colSList.append('"%s"'% name) 
    397404                    valList.append(self.__attrVal2sql(d[l[i]])) 
    398                 valStr = ', '.join(["%s"]*len(colList)) 
    399                 cursor.execute(query % (table, 
     405                d = query % (table, 
    400406                    ", ".join(colSList), 
    401                     ", ".join (["%s"] * len(valList))), tuple(valList)) 
     407                    ", ".join ([self.quirks.parameter] * len(valList))) 
     408                print d, valList 
     409                cursor.execute(d, tuple(valList)) 
    402410            cursor.close() 
    403411            self.connection.commit() 
     
    408416 
    409417    @deprecated_keywords({"renameDict":"rename_dict", "typeDict":"type_dict"}) 
    410     def create(self, table, instances, rename_dict = None, type_dict = None): 
     418    def create(self, table, instances, rename_dict = {}, type_dict = {}): 
    411419        """ 
    412420        Create the required SQL table, then write the data into it. 
     
    431439        if instances.domain.class_var: 
    432440            l.append((instances.domain.class_var.name, instances.domain.class_var.var_type)) 
    433         if rename_dict is None: 
    434             renameDict = {} 
     441        #if rename_dict is None: 
     442        #    rename_dict = {} 
    435443        colNameList = [rename_dict.get(str(i[0]), str(i[0])) for i in l] 
    436         if type_dict is None: 
    437             typeDict = {} 
     444        #if type_dict is None: 
     445        #    typeDict = {} 
    438446        colTypeList = [type_dict.get(str(i[0]), self.__attrType2sql(i[1])) for i in l] 
    439447        try: 
     
    446454            self.quirks.beforeCreate(cursor) 
    447455            cursor.execute(query) 
    448             print query 
    449456            self.write(table, instances, rename_dict) 
    450457            self.connection.commit() 
Note: See TracChangeset for help on using the changeset viewer.