Python论坛  - 讨论区

标题:[python-chinese] from access extract sql, isql for access

2005年07月06日 星期三 10:08

mahongquan mahongquan730208 at 163.com
Wed Jul 6 10:08:38 HKT 2005

Skipped content of type multipart/alternative-------------- next part --------------
cmds=[
"""CREATE TABLE [CaliHis] (
 [id] integer not null ,
 [mdate] datetime null ,
 [methodid] integer null ,
 [ele] varchar(2.0) null ,
 [useXiaoZheng] smallint null ,
 [dxielv] float null ,
 [djieju] float null 
  ) 
""",
"""Alter TABLE [CaliHis]  ADD Primary Key([id] ) [PK_CaliHis]""",



"""CREATE TABLE [chanel] (
 [ele] varchar(50.0) null ,
 [id] integer not null ,
 [chanel] smallint null 
  ) 
""",
"""Alter TABLE [chanel]  ADD Primary Key([id] ) [PK_chanel]""",



"""CREATE TABLE [curveData] (
 [methodid] integer null ,
 [standardid] integer null ,
 [eleArea] float null ,
 [eleInt] float null ,
 [ele] varchar(2.0) null ,
 [weight] float null ,
 [id] integer not null ,
 [calcconc] float null ,
 [sampleid] integer null ,
 [quan] float null ,
 [wlweight] float null 
  ) 
""",
"""Alter TABLE [curveData]  ADD Primary Key([id] ) [PK_curveData]""",



"""CREATE TABLE [CurveHis] (
 [id] integer not null ,
 [methodid] integer null ,
 [mdate] datetime null ,
 [x0] float null ,
 [x1] float null ,
 [x2] float null ,
 [x3] float null ,
 [ele] varchar(2.0) null ,
 [r] float null ,
 [cishu] integer null ,
 [stderr] float null ,
 [LINExishu] real null ,
 [min] float null ,
 [max] float null 
  ) 
""",
"""Alter TABLE [CurveHis]  ADD Primary Key([id] ) [PK_CurveHis]""",



"""CREATE TABLE [curveXishu] (
 [methodid] integer not null ,
 [x0] float null ,
 [x1] float null ,
 [x2] float null ,
 [x3] float null ,
 [ele] varchar(2.0) not null ,
 [xadd] float null ,
 [r] float null ,
 [fitMode] integer null ,
 [cishu] integer null ,
 [stderr] float null ,
 [LINExishu] real null ,
 [calcmode] smallint null ,
 [useXiaoZheng] smallint null ,
 [dxielv] float null ,
 [djieju] float null ,
 [UseInt] bit not null ,
 [min] float null ,
 [max] float null ,
 [blankarea] float null ,
 [must00] bit not null 
  ) 
""",
"""Alter TABLE [curveXishu]  ADD Primary Key([methodid] ,[ele] ) [PK_curveXishu]""",



"""CREATE TABLE [doChanel] (
 [cname] varchar(50.0) null ,
 [id] integer not null ,
 [chanel] smallint null 
  ) 
""",
"""Alter TABLE [doChanel]  ADD Primary Key([id] ) [PK_doChanel]""",



"""CREATE TABLE [doublestandard] (
 [ID] integer not null ,
 [standardid] integer not null ,
 [methodid] integer not null ,
 [ele] varchar(2.0) not null ,
 [calcConc] float null ,
 [high] bit not null ,
 [eleArea] float null ,
 [weight] float null 
  ) 
""",
"""Alter TABLE [doublestandard]  ADD Primary Key([standardid] ,[methodid] ,[ele] ) [PK_doublestandard]""",



"""CREATE TABLE [method] (
 [ID] integer not null ,
 [user] varchar(50.0) not null ,
 [name] varchar(50.0) not null ,
 [power] integer null ,
 [zerovalue] real null ,
 [useJiaozheng] bit not null ,
 [cswitch] float null ,
 [sswitch] float null ,
 [smoothnum] smallint null ,
 [sampletime] integer null ,
 [flushtime] integer null 
  ) 
""",
"""Alter TABLE [method]  ADD Primary Key([user] ,[name] ) [PK_method]""",



"""CREATE TABLE [muser] (
 [ID] integer not null ,
 [mname] varchar(50.0) not null ,
 [autoweight] bit not null ,
 [mpassword] varchar(10.0) null ,
 [method] varchar(50.0) null ,
 [methodid] integer null 
  ) 
""",
"""Alter TABLE [muser]  ADD Primary Key([mname] ) [PK_muser]""",



"""CREATE TABLE [mytmp] (
 [methodid] integer null ,
 [standardid] integer null ,
 [eleArea] float null ,
 [eleInt] float null ,
 [ele] varchar(2.0) null ,
 [weight] float null ,
 [calcconc] float null ,
 [sampleid] integer null 
  ) 
""",
"""CREATE INDEX [] on [mytmp]() """,



"""CREATE TABLE [netSet] (
 [ip] varchar(50.0) null ,
 [port] integer null ,
 [prot] bit not null ,
 [id] integer not null 
  ) 
""",
"""Alter TABLE [netSet]  ADD Primary Key([id] ) [PK_netSet]""",



"""CREATE TABLE [program] (
 [tablehead1] varchar(50.0) null ,
 [tablehead2] varchar(50.0) null ,
 [id] integer not null ,
 [sampleId] integer null ,
 [isON] bit not null ,
 [xuhao] smallint null ,
 [sessionid] integer null ,
 [lastUser] varchar(50.0) null ,
 [autoLogon] bit not null 
  ) 
""",
"""Alter TABLE [program]  ADD Primary Key([id] ) [PK_program]""",



"""CREATE TABLE [sample] (
 [ID] integer not null ,
 [name] varchar(50.0) null ,
 [cArea] float null ,
 [c] real null ,
 [sArea] float null ,
 [s] real null ,
 [mdate] datetime null ,
 [user] varchar(50.0) null ,
 [weight] float null ,
 [method] varchar(50.0) null ,
 [methodid] integer null ,
 [isHc] bit not null ,
 [isHs] bit not null ,
 [sessionid] integer null ,
 [sampleid] integer null ,
 [anaxuhao] integer null ,
 [cInt] float null ,
 [sInt] float null ,
 [sIndex] integer null ,
 [cIndex] integer null ,
 [standardid] integer null ,
 [sIndex2] integer null ,
 [cIndex2] integer null ,
 [wlweight] float null 
  ) 
""",
"""Alter TABLE [sample]  ADD Primary Key([ID] ) [PK_sample]""",



"""CREATE TABLE [SampleAve] (
 [sessionid] integer null ,
 [sampleid] integer not null ,
 [c] real null ,
 [s] real null ,
 [mdate] datetime null ,
 [name] varchar(255.0) null ,
 [user] varchar(20.0) null ,
 [methodid] integer null ,
 [num] smallint null ,
 [cstd] float null ,
 [sstd] float null 
  ) 
""",
"""Alter TABLE [SampleAve]  ADD Primary Key([sampleid] ) [PK_SampleAve]""",



"""CREATE TABLE [SingleStandard] (
 [ID] integer not null ,
 [standardid] integer null ,
 [eleArea] float null ,
 [weight] float null ,
 [methodid] integer null ,
 [ele] varchar(2.0) null ,
 [IsBlank] bit not null ,
 [xishu] float null ,
 [calcConc] float null 
  ) 
""",
"""Alter TABLE [SingleStandard]  ADD Primary Key([ID] ) [PK_SingleStandard]""",



"""CREATE TABLE [standard] (
 [ID] integer not null ,
 [name] varchar(50.0) null ,
 [cconc] real null ,
 [sconc] real null ,
 [description] varchar(50.0) null ,
 [userid] integer null 
  ) 
""",
"""Alter TABLE [standard]  ADD Primary Key([ID] ) [PK_standard]""",



"""CREATE TABLE [tmp] (
 [methodid] integer null ,
 [standardid] integer null ,
 [sampleid] integer null ,
 [ele] varchar(2.0) null ,
 [elearea] float null ,
 [weight] float null ,
 [quan] float null 
  ) 
""",
"""CREATE INDEX [] on [tmp]() """,



"""CREATE TABLE [tmpid] (
 [sampleid] integer not null 
  ) 
""",
"""Alter TABLE [tmpid]  ADD Primary Key([sampleid] ) [PK_tmpid]""",



"""CREATE TABLE [tmpReport] (
 [id] integer not null ,
 [sessionid] integer null ,
 [sampleid] integer null ,
 [c] real null ,
 [s] real null ,
 [mdate] datetime null ,
 [name] varchar(255.0) null ,
 [user] varchar(20.0) null ,
 [methodid] integer null ,
 [num] smallint null ,
 [cstd] float null ,
 [sstd] float null 
  ) 
""",
"""Alter TABLE [tmpReport]  ADD Primary Key([id] ) [PK_tmpReport]""",



"""CREATE TABLE [usehistory] (
 [ID] integer not null ,
 [user] varchar(50.0) null ,
 [starttime] datetime null ,
 [endtime] datetime null 
  ) 
""",
"""Alter TABLE [usehistory]  ADD Primary Key([ID] ) [PK_usehistory]""",



"""CREATE TABLE [volt] (
 [mtime] float null ,
 [cvolt] float null ,
 [svolt] float null ,
 [sampleid] integer null ,
 [id] integer not null ,
 [c2volt] float null ,
 [s2volt] float null 
  ) 
""",
"""CREATE Unique INDEX [id1] on [volt]([id] ) """,



"""CREATE TABLE [VoltNew] (
 [sampleid] integer not null ,
 [mtimeArr] text null ,
 [cvoltArr] text null ,
 [svoltArr] text null ,
 [c2voltArr] text null ,
 [s2voltArr] text null ,
 [xn] integer null ,
 [yn0] integer null ,
 [yn1] integer null ,
 [yn2] integer null ,
 [yn3] integer null 
  ) 
""",
"""Alter TABLE [VoltNew]  ADD Primary Key([sampleid] ) [PK_VoltNew]""",



"""CREATE TABLE [weight] (
 [id] integer not null ,
 [time] datetime null ,
 [name] varchar(50.0) null ,
 [weight] float null 
  ) 
""",
"""Alter TABLE [weight]  ADD Primary Key([id] ) [PK_weight]""",


]
-------------- next part --------------
##改编马红权2005-07-06
##原作者:2004-11-18    ====MiniAcces Editor1.0part2 Access SQL脚本编写器(V37 PaintBlue.Net 2004 Acp Code)=========
from vb2py.vbfunctions import Variant,String,Chr,IsNumeric,Len,Instr,CreateObject,vbCrLf,Mid,vbForRange,LCase,Left,Right
import Module1
import win32com.client
InStr=Instr
def IsNull(a):
    if a.Value==None:
        return(1)
    else:
        return(0)
def Replace(a,b,c):
    return(a)
class Ma:
    def __init__(self):
        self.db_name='J:\\nb\\cs\\access2000\\data.mdb'
        self.rs=None
    def setDbName(self,mdbName):
        self.db_name=mdbName
    def on_Command1_mouseClick(self, event=None):
        db_name = self.db_name
        self.createAccessSql(db_name)
    def createAccessSql(self,db_name):
        remchar=""
        TtempStr=""
        TableStr=""
        self.rs = CreateObject('adodb.recordSet')
        self.__connstr = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + db_name
        self.__conn = CreateObject('ADODB.Connection')
        self.__conn.Open(self.__connstr)
        #编写表/索引对象
        tbls = self.__conn.openSchema(20)
        tbls.Filter = ' TABLE_TYPE=\'TABLE\' '
        while not tbls.EOF:
            TableStr = TableStr + '|' + tbls.Fields['TABLE_Name'].Value
            tbls.MoveNext()
        tbls.Filter = 0
        tbls.Close()
        tbls = None
        TableStr = Mid(TableStr, 2)
        isexec=0
        if TableStr 
 '':
            tabsArr = TableStr.split('|')
            ub = len(tabsArr)
            for i in range(ub):
                TtempStr = TtempStr + self.CreatTableSql(tabsArr[i]) + vbCrLf + vbCrLf
        f=open("cmd.py","w")
        f.write("cmds=["+TtempStr+"]")
        f.close()
        print TtempStr
    #~ def __CreatViewSql(self, isexec):
        #~ _ret = None
        #~ tmpstr=""
        #~ cols = self.__conn.openSchema(23)
        #~ cols.Filter = 0
        #~ while not cols.EOF:
            #~ TmpStr1 = ''
            #~ VIEW_DEFINITION = Replace(cols('VIEW_DEFINITION').Value, Chr(13), '')
            #~ print "=================",VIEW_DEFINITION
            #~ VIEW_DEFINITION = Replace(VIEW_DEFINITION, Chr(10), ' ')
            #~ VIEW_DEFINITION = Left(VIEW_DEFINITION, Len(VIEW_DEFINITION) - 1)
            #~ VIEW_DEFINITION = self.__TransView(cols('TABLE_NAME'), VIEW_DEFINITION)
            #~ TmpStr1 = 'Create view [dbo].[' + cols('TABLE_NAME').Value + '] As ' + VIEW_DEFINITION + ''
            #~ if isexec == 1:
                #~ TmpStr1 = 'CONN.execute("' + TmpStr1 + '")'
            #~ tmpstr = tmpstr + vbCrLf + TmpStr1
            #~ if isexec == 0:
                #~ tmpstr = tmpstr + vbCrLf + ' go'
            #~ cols.MoveNext()
        #~ cols.Close()
        #~ cols = None
        #~ _ret = tmpstr
        #~ return _ret
    #~ def __TransView(self, viewName, Str):
        #~ _ret = None
        #~ s = LCase(Str)
        #~ s = Replace(s, Chr(9), ' ')
        #~ s = Replace(s, Chr(32), ' ')
        #~ s = Replace(s, Chr(10), ' ')
        #~ s = Replace(s, Chr(13), '')
        #~ s = Replace(s, ';', ' ')
        #~ while InStr(s, '  ') > 0:
            #~ s = Replace(s, '  ', ' ')
        #~ s = Replace(s, 'count(*)', 'count(*) as count_x')
        #~ if InStr(LCase(s), '* from') == 0:
            #~ _ret = s
        #~ else:
            #~ _ret = Replace(s, '* from', self.__GetviewColumnStr(viewName) + ' from')
        #~ #rw GetviewColumnStr(viewName),1
        #~ #rw instr(lcase(S),"* from"),1
        #~ return _ret
    #~ def __GetviewColumnStr(self, viewName):
        #~ _ret = None
        #~ chg = False
        #~ #rw "[" & viewName & "]",0
        #~ rs = CreateObject('adodb.recordset')
        #~ #rw "select * from [" & tablename & "] where 1=0",1
        #~ rs.Open('[' + viewName + ']', self.__conn)
        #~ if rs.fields.Count > 0:
            #~ tmpstr = rs(0).Name
            #~ for i in vbForRange(1, rs.fields.Count - 1):
                #~ tmpstr = tmpstr + ',' + rs(i).Name
            #~ tmpstr = LCase(tmpstr)
            #~ arr = Split(tmpstr, ',')
            #~ for i in vbForRange(0, UBound(arr)):
                #~ tmp = arr[i]
                #~ arr[i] = '[' + arr[i] + ']'
                #~ if InStr(arr[i], '.') > 0:
                    #~ arr[i] = Replace(arr(i), '.', '].[')
                    #~ arr[i] = arr[i] + ' as ' + Replace(tmp, '.', '_')
                    #~ chg = True
            #~ if chg:
                #~ _ret = Join(arr, ',')
            #~ else:
                #~ _ret = '*'
        #~ else:
            #~ _ret = ''
        #~ return _ret

    def CreatTableSql(self, tablename):
        _ret = None
        isexec=0
        cols = self.__conn.openSchema(4)
        splitchar = ''
        splitchar1 = ''
        cols.Filter = 'Table_name=\'' + tablename + '\''
        if cols.EOF:
            return _ret
        n = 0
        # 编写表脚本
        autoclumn = self.__GetAutoincrementCoulmnT(tablename)
        TmpStr1 = '"""CREATE TABLE [' + tablename + '] (' + splitchar1 + vbCrLf
        if autoclumn 
 None:
            autoclumnStr = '    ' + splitchar + '[' + autoclumn + '] autoincrement'
        n = 0
        while 1:
            n = n + 1
            cols.Filter = 'Table_name=\'' + str(tablename) + '\' and ORDINAL_POSITION=' + str(n)
            if cols.EOF:
                break
            if n > 1:
                TmpStr1 = TmpStr1 + ',' + splitchar1 + vbCrLf
            if autoclumn == cols('Column_name'):
                TmpStr1 = TmpStr1 + autoclumnStr
            else:
                #print cols('Column_name')
                #print splitchar
                s1=self.__datatypeStr(cols('DATA_TYPE'), cols('CHARACTER_MAXIMUM_LENGTH'))
                s1=LCase(s1)
                s2=self.__nullStr(cols('IS_NULLABLE'), tablename, cols('Column_name'))
                s3=""##self.__defaultStr(cols('DATA_TYPE'), cols('COLUMN_DEFAULT'), isexec)
                TmpStr1 = TmpStr1 + ' ' + splitchar + '[' + str(cols('Column_name')) + '] ' + s1 + s3 + s2
            cols.MoveNext()
        TmpStr1 = TmpStr1 + splitchar1 + vbCrLf + '  ' + splitchar + ') '
        cols.Close()
        TmpStr1 = TmpStr1 + splitchar1 + vbCrLf + '' + splitchar + '""",'
        tmpstr=""
        tmpstr = tmpstr + vbCrLf + TmpStr1
        # 编写索引脚本
        s11=self.__getInxArr(tablename)
        InxArr = s11.split(',')
        cols = self.__conn.openSchema(12)
        for i in range(len(InxArr)):
            cols.Filter = 'Table_name=\'' + tablename + '\' and index_name=\'' + InxArr[i] + '\''
            kstr = ''
            TmpStr1 = ''
            if not self.__isForeignIndex(tablename, InxArr[i]):
                while not cols.EOF:
                    kstr = kstr + ',[' + cols('column_name').Value + '] ' + self.__GetInxDesc(tablename, InxArr[i], cols('column_name'))
                    cols.MoveNext()
                if self.__isPrimaryKey(tablename, InxArr[i]):
                    TmpStr1 = TmpStr1 + '"""Alter TABLE [' + tablename + ']  ADD Primary Key(' + Mid(kstr, 2) + ') [PK_' + tablename + ']""",'
                else:
                    TmpStr1 = TmpStr1 + '"""CREATE '
                    if self.__isUnique(tablename, InxArr[i]):
                        TmpStr1 = TmpStr1 + 'Unique '
                    TmpStr1 = TmpStr1 + 'INDEX [' + InxArr[i] + '] on [' + tablename + '](' + Mid(kstr, 2) + ') """,'
                TmpStr1 = TmpStr1 + vbCrLf 
                tmpstr = tmpstr + vbCrLf + TmpStr1
        cols.Close()
        cols.Filter = 0
        _ret = tmpstr
        return _ret
    def __GetColumnStr(self, tablename):
        _ret = None
        rs = CreateObject('adodb.recordset')
        #rw "select * from [" & tablename & "] where 1=0",1
        cmd='select * from [' + tablename.Value + '] where 1=0'
        print cmd
        print self.__conn
        print rs
        tmpstr=""
        rs.Open(cmd, self.__conn)
        if rs.fields.Count > 0:
            for i in vbForRange(0, rs.fields.Count - 1):
                #rw rs(i).name & "_" & rs(i).type & "
",1 if rs(i).Type
205: tmpstr = tmpstr + ',' + rs(i).Name if tmpstr
'': _ret = Mid(tmpstr, 2) _ret = '' else: _ret = '' return _ret def __Ac2SQLStr(self): tmpstr = '' rs = self.__conn.openSchema(20) rs.Filter = 'TABLE_TYPE=\'TABLE\'' while not rs.EOF: tmpstr = tmpstr + 'SELECT * INTO [tmp_' + rs('TABLE_NAME') + '] FROM OPENDATASOURCE(\'Microsoft.Jet.OLEDB.4.0\',\'Data Source="d:\\www\\lfgbox\\paintblue2.0f2\\pbbs\\database\\paintbase#.asa"\')...[' + rs('TABLE_NAME') + ']
' NN = NN + 1 rs.MoveNext() rs.Filter = 0 rs.Close() rs = None def __isForeignIndex(self, tablename, IndexName): _ret = None cols = self.__conn.openSchema(27) cols.Filter = 'FK_TABLE_Name=\'' + tablename + '\' and FK_NAME=\'' + IndexName + '\'' if not cols.EOF: _ret = True else: _ret = False return _ret def __GetInxDesc(self, tablename, IndexName, columnName): _ret = None cat = CreateObject('ADOX.Catalog') cat.ActiveCONNection = self.__connstr t=cat.Tables('' + tablename + '') i=t.Indexes('' + IndexName + '') c=i.Columns('' + columnName.Value + '') if c.SortOrder == 2: _ret = 'Desc' else: _ret = '' cat = None return _ret def __getColumArr(self, tablename): _ret = None arr = vbObjectInitialize((- 1,), Variant) n = 0 arr = vbObjectInitialize((n,), Variant) cols = self.__conn.openSchema(4) cols.Filter = 'Table_Name=\'' + tablename + '\'' while not cols.EOF: arr = vbObjectInitialize((n,), Variant, arr) arr[n] = cols('column_name') cols.MoveNext() n = n + 1 cols.Filter = 0 cols.Close() cols = None _ret = arr return _ret def __getInxArr1(self, tablename): _ret = None arr = vbObjectInitialize((- 1,), Variant) n = 0 cols = self.__conn.openSchema(12) cols.Filter = 'Table_Name=\'' + tablename + '\'' while not cols.EOF: if cols('index_name')
tmpCol: arr = vbObjectInitialize((n,), Variant, arr) arr[n] = cols('index_name') n = n + 1 tmpCol = cols('index_name') cols.MoveNext() cols.Filter = 0 cols.Close() cols = None ##self.__getInxArr() = arr return _ret def __getInxArr(self, tablename): _ret = None n = 0 tmpCol=None tmps="" cols = self.__conn.openSchema(12) cols.Filter = 'Table_Name=\'' + tablename + '\'' while not cols.EOF: if cols('index_name')
tmpCol: tmps = tmps + ',' + cols('index_name').Value n = n + 1 tmpCol = cols('index_name') cols.MoveNext() cols.Filter = 0 cols.Close() cols = None _ret = Mid(tmps, 2) return _ret def __isUnique(self, tablename, IndexName): _ret = None cols = self.__conn.openSchema(12) cols.Filter = 'Table_Name=\'' + tablename + '\' and Index_Name=\'' + IndexName + '\' and UNIQUE=True' if not cols.EOF: _ret = True else: _ret = False cols.Filter = 0 cols.Close() cols = None return _ret def __isPrimaryKey(self, tablename, IndexName): _ret = None cols = self.__conn.openSchema(12) cols.Filter = 'Table_Name=\'' + str(tablename) + '\' and Index_Name=\'' + IndexName + '\' and PRIMARY_KEY=True' if not cols.EOF: _ret = True else: _ret = False cols.Filter = 0 cols.Close() cols = None return _ret def __getPrimaryKey(self, tablename, columnName): _ret = None cols = self.__conn.openSchema(12) cols.Filter = 'Table_Name=\'' + str(tablename) + '\' and Column_Name=\'' + str(columnName.Value) + '\' and PRIMARY_KEY=True' if not cols.EOF: _ret = cols('INDEX_NAME') #isPrimaryKey=true else: _ret = '' #isPrimaryKey=false cols.Filter = 0 cols.Close() cols = None return _ret def __existPrimaryKey(self, tablename): _ret = None cols = self.__conn.openSchema(12) cols.Filter = 'Table_Name=\'' + tablename + '\' and PRIMARY_KEY=True' if not cols.EOF: _ret = True else: _ret = False cols.Filter = 0 cols.Close() cols = None return _ret def __GetIncrement(self, tablename, columnName): _ret = "" cat = CreateObject('ADOX.Catalog') cat.ActiveCONNection = self.__connstr print tablename,columnName _ret = cat.Tables[ tablename ].Columns[ columnName].Properties['Increment'] cat = None return _ret def __GetSeed(self, tablename, columnName): _ret = None cat = Server.CreateObject('ADOX.Catalog') cat.ActiveCONNection = self.__connstr _ret = cat.Tables('' + tablename + '').Columns('' + columnName + '').Properties('Seed') cat = None return _ret def __GetAutoincrementCoulmnT(self, tablename): _ret = None self.rs.Open('select * from [' + tablename + '] where 1=0', self.__conn, 0, 1) for i in vbForRange(0, self.rs.fields.Count - 1): #if rs(i).Properties("isAutoIncrement")=True then if self.rs(i).Properties('isAutoIncrement') == True: _ret = self.rs(i).Name self.rs.Close() return _ret self.rs.Close() return _ret def __datatypeStr(self, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH): _ret = None _select0 = DATA_TYPE.Value #~ print type(CHARACTER_MAXIMUM_LENGTH) #~ print dir(CHARACTER_MAXIMUM_LENGTH) #~ print type(CHARACTER_MAXIMUM_LENGTH.Value) #~ print CHARACTER_MAXIMUM_LENGTH.Value if (_select0 == 130): if CHARACTER_MAXIMUM_LENGTH.Value == 0: _ret = 'text' else: _ret = 'varchar(' + str(CHARACTER_MAXIMUM_LENGTH.Value) + ')' elif (_select0 == 17): _ret = 'tinyint' elif (_select0 == 2): _ret = 'Smallint' elif (_select0 == 3): _ret = 'integer' elif (_select0 == 4): _ret = 'real' elif (_select0 == 5): _ret = 'float' elif (_select0 == 6): _ret = 'money' elif (_select0 == 7): _ret = 'datetime' elif (_select0 == 11): _ret = 'bit' elif (_select0 == 72): _ret = 'UNIQUEIDENTIFIER' elif (_select0 == 131): _ret = 'DECIMAL' elif (_select0 == 128): _ret = 'BINARY' return _ret def __defaultStr(self, DATA_TYPE, COLUMN_DEFAULT, isexec): _ret = None if IsNull(COLUMN_DEFAULT): _ret = '' return _ret if isexec == 1: splitchar = '""' elif isexec == 0: splitchar = '"' COLUMN_DEFAULT = self.__defaultStrfilter(COLUMN_DEFAULT) _select1 = DATA_TYPE if (_select1 == 130): COLUMN_DEFAULT = Replace(COLUMN_DEFAULT, '"', splitchar) _ret = ' Default (\'' + COLUMN_DEFAULT + '\')' elif (_select1 == 11): if LCase(COLUMN_DEFAULT) == 'true' or LCase(COLUMN_DEFAULT) == 'on' or LCase(COLUMN_DEFAULT) == 'yes': COLUMN_DEFAULT = 1 COLUMN_DEFAULT = 0 _ret = ' Default (' + COLUMN_DEFAULT + ')' elif (_select1 == 128): _ret = ' Default (0x' + COLUMN_DEFAULT + ')' elif (_select1 == 7): if LCase(COLUMN_DEFAULT) == 'now()' or LCase(COLUMN_DEFAULT) == 'date()' or LCase(COLUMN_DEFAULT) == 'time()': COLUMN_DEFAULT = 'getdate()' if Left(COLUMN_DEFAULT, 1) == '#': COLUMN_DEFAULT = Replace(COLUMN_DEFAULT, '#', '\'') _ret = ' Default (' + COLUMN_DEFAULT + ')' else: _ret = ' Default (' + COLUMN_DEFAULT + ')' return _ret def __defaultStrfilter(self, s): _ret = None s=str(s.Value) while Left(s, 1) == '"': s = Mid(s, 2) while Right(s, 1) == '"': s = Left(s, Len(s) - 1) while Left(s, 1) == '\'': s = Mid(s, 2) while Right(s, 1) == '\'': s = Left(s, Len(s) - 1) _ret = s return _ret def __nullStr(self, IS_NULLABLE, tablename, columnName): _ret = None if IS_NULLABLE.Value: if self.__getPrimaryKey(tablename, columnName) == '': _ret = ' null ' else: _ret = ' not null ' else: _ret = ' not null ' return _ret if __name__ == '__main__': a=Ma() a.setDbName('J:\\ncs_cs\\src\\access_2000\\data.mdb') a.on_Command1_mouseClick() -------------- next part -------------- import win32com.client import pywintypes from isql2 import Aisql import cmd def connect(dbfn): try: constr=r"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+dbfn+";Persist Security Info=False" print constr db=Aisql() db.dbConnect("",constr) return(db) except pywintypes.com_error,e: print e[0],e[1] except: print "error" if __name__=="__main__": dbfn=r"J:\nb\cs\access2000\data.mdb" db=connect(dbfn) if db!=None: for cmd1 in cmd.cmds: try: r=db.execQuery(cmd1) except pywintypes.com_error,e: if e[0]==-2147352567: pass else: print e[0],e[1] else: print "error open" -------------- next part -------------- #import gadfly #import sqlite #import odbc import win32com.client #from pyPgSQL import PgSQL class isql: def __init__(self): self.database=None def dbConnect(self,directory,db): pass def getTables(self): pass def execQuery(self,str1): curs = self.database.cursor() curs.execute(str1) r=self.pp(curs) self.database.commit() return(r) def pp(self,cursor): try: rows = cursor.fetchall() except: return "No description" desc = cursor.description i=0 n=len(desc) r=[] r1=[] while i

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年07月06日 星期三 10:30

Zoom Quiet zoom.quiet at gmail.com
Wed Jul 6 10:30:56 HKT 2005

好也!!
方便的话解说一下子:
http://wiki.woodpecker.org.cn/moin/MicroProj/2005-07-06

在 05-7-6,mahongquan<mahongquan730208 at 163.com> 写道:
>  
> 我写的isql for access,和改编自蓝色理想网站的 access to sql,
> 大家看有用吗,里面用到win32com,vb2py等模块。 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 
> 
> 
> 


-- 
[Time is unimportant, only life important!]

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年07月06日 星期三 13:17

mahongquan mahongquan730208 at 163.com
Wed Jul 6 13:17:22 HKT 2005

应该不难理解。只是有些涉及到win32com的地方难理解一些。
----- Original Message ----- 
From: "Zoom Quiet" <zoom.quiet at gmail.com>
To: <python-chinese at lists.python.cn>; "Python.cn at google" <python-cn at googlegroups.com>
Sent: Wednesday, July 06, 2005 10:30 AM
Subject: Re: [python-chinese] from access extract sql, isql for access


> 好也!!
> 方便的话解说一下子:
> http://wiki.woodpecker.org.cn/moin/MicroProj/2005-07-06
> 
> 在 05-7-6,mahongquan<mahongquan730208 at 163.com> 写道:
> >  
> > 我写的isql for access,和改编自蓝色理想网站的 access to sql,
> > 大家看有用吗,里面用到win32com,vb2py等模块。 
> > _______________________________________________
> > python-chinese list
> > python-chinese at lists.python.cn
> > http://python.cn/mailman/listinfo/python-chinese
> > 
> > 
> > 
> > 
> 
> 
> -- 
> [Time is unimportant, only life important!]
> 


--------------------------------------------------------------------------------


> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号