Esempio n. 1
0
    def getTableDependencies(tabDict):
        localTab = "mTab"
        toRet = "Static Function /Wave GetDependencies({:s})\n".format(localTab)
        mTables,ids = IgorConvert.getAllTableIds(tabDict)
        mSwitch = IgorConvert.getTableSwitchStr(localTab,mTables)
        switchFmt = []
        toRet += "\tString {:s}\n".format(localTab)
        mRet = "toRetTabDep"
        for tab in mTables:
            tableField = tabDict[tab]
            names,fields = SqlDefine.getNameType(tableField)
            sqlTypes = IgorConvert.getSqlTypes(tab,names,fields)
            mList = []
            for fieldName,fieldType in zip(names,sqlTypes):
                if (fieldType == HandlerTypes.Foreignkey):
                    mKey = IgorConvert.foreignKeyToTableName(fieldName)
                    # make sure we are consistent

                    assert mKey in mTables
                    # POST: table exists
                    mList.append(IgorConvert.getTableConstName(mKey))
            # POST: mList is populated with 0 or more elements.
            # create a wave for this. False: don't add quoates
            nEle = len(mList)
            myMake = IgorConvert.getMakeTextFromList(mRet,mList,False)
            switchFmt.append(myMake)
        # format all the items we have made
        formatted = mSwitch.format(*switchFmt)
        # return the relevant wavt
        toRet += formatted
        toRet += "\tReturn {:s}\n".format(mRet)
        toRet += "End Function\n"
        return toRet
Esempio n. 2
0
 def getTypeByTable(tableDict):
     mTables,_ = IgorConvert.getAllTableIds(tableDict)
     tabName = "mTab"
     toRet = "Static Function /Wave GetTypesByTable({:s})\n".\
             format(tabName)
     toRet += "\tString {:s}\n".format(tabName)
     mSwitch = IgorConvert.getTableSwitchStr(tabName,mTables)
     switchFmt = []
     localToRet = "toRetColType"
     for tab in mTables:
         fieldNames,fieldTypes = SqlDefine.getNameType(tableDict[tab])
         mSqlTypeList = IgorConvert.getSqlTypes(tabName,fieldNames,
                                                fieldTypes)
         mList = IgorConvert.getMakeFromList(localToRet,mSqlTypeList)
         switchFmt.append( "{:s}".format(mList))
     finalSwitch = mSwitch.format(*switchFmt)
     toRet += finalSwitch
     toRet += "\treturn {:s}\n".format(localToRet)
     toRet += "End Function\n"
     return toRet
Esempio n. 3
0
 def getColByTableID(tableDict):
     localTabName = "mTab"
     mTables,_ = IgorConvert.getAllTableIds(tableDict)
     mSwitch = IgorConvert.getTableSwitchStr(localTabName,mTables)
     toRet = "Static Function /Wave GetColByTable({:s})\n".\
             format(localTabName)
     toRet += "\tString {:s}\n".format(localTabName)
     switchFmt = []
     mRet = "toRetColTab"
     for tmpTable in mTables:
         tableFieldsDict = tableDict[tmpTable]
         # get all of ou field names
         names,_ = SqlDefine.getNameType(tableFieldsDict)
         mList = [IgorConvert.getFieldName(f) for f in names]
         # False: dont add quotes
         switchFmt.append(IgorConvert.getMakeTextFromList(mRet,mList,False))
     # POST: switchFmt is done
     finalSwitch = mSwitch.format(*switchFmt)
     toRet += finalSwitch
     toRet += "\treturn {:s}\n".format(mRet)
     toRet += "End Function\n"
     return toRet
Esempio n. 4
0
 def getDependenciesOnTable(tabDict):
     localTab = "mTab"
     toRet = "Static Function /Wave GetWhatDependsOnTable({:s})\n".\
             format(localTab)
     toRet += "\tString {:s}\n".format(localTab)
     mTables,ids = IgorConvert.getAllTableIds(tabDict)
     mSwitch = IgorConvert.getTableSwitchStr(localTab,mTables)
     mDependencies = defaultdict(list)
     for mTab in mTables:
         # get the types
         tableField  = tabDict[mTab]
         names,fields = SqlDefine.getNameType(tableField)
         sqlTypes = IgorConvert.getSqlTypes(mTab,names,fields)
         mList = []
         for name,mType in zip(names,sqlTypes):
             if (mType == HandlerTypes.Foreignkey):
                 # them 'mTab' references whatever table is here
                 sourceTable = IgorConvert.foreignKeyToTableName(name)
                 mDependencies[sourceTable].append(mTab)
     # POST: mDependencies[<name>] has all of the tables depending on 
     # <name>. 
     finalList = []
     # which tables (keys) have dependencies?
     keys = sorted(mDependencies.keys())
     localRet = "toRetDependencies"
     for mTab in mTables:
         # get the (possibly empty) list of dependencies
         mList = sorted(mDependencies[mTab]) if mTab in keys else []
         # get the contsants associated with this name
         mTabConstList = [IgorConvert.getTableConstName(t) for t in mList]
         # convert to a make text. False: dont add quotes
         mStr = IgorConvert.getMakeTextFromList(localRet,mTabConstList,False)
         finalList.append(mStr)
     # post: fill in mSwitch
     toRet += mSwitch.format(*finalList)
     toRet += "\treturn {:s}\n".format(localRet)
     toRet += "End Function\n"
     return toRet
Esempio n. 5
0
 def getDBString(self,strBetweenTables="\n",
                 funcTableToConst=IgorConvert.getTableConst,
                 funcTableToStruct=IgorConvert.getStructs,
                 funcTableToInsert=IgorConvert.getInsertFuncs,
                 funcColNames=IgorConvert.getColNameWaveFunc,
                 funcFieldConstants=IgorConvert.getFieldConstants,
                 funcInitStructs=IgorConvert.InitStructs,
                 funcAllTables=IgorConvert.getAllTables,
                 funcConversions=IgorConvert.getConverts,
                 funcSelect=IgorConvert.getSelectFuncs,
                 funcHandlers=IgorConvert.getHandlers,
                 funcId=IgorConvert.getTableIdMethods,
                 funcHandleGlobal=IgorConvert.getHandleGlobal):
     # must have called 
     tableDict = self._mDict
     allFields = self._allFields
     structString = ""
     constString = ""
     insertString = ""
     colNameString = ""
     fieldNameString =""
     initStructString = ""
     selectString = ""
     convertString = ""
     # add each element of the tables
     mKeys = sorted(tableDict.keys())
     mTableString = funcAllTables(tableDict)
     fieldNameString += funcFieldConstants(allFields)
     idTableString = funcId(tableDict)
     handlerString = funcHandleGlobal(tableDict)
     for table in mKeys:
         mTableField = tableDict[table]
         # look through each element, corresponding to a separate field.
         namesTmp,typeTmp = SqlDefine.getNameType(mTableField)
         # POST: all elements accounted for... 
         # XXX make more efficient, store this way?
         constString += funcTableToConst(table)
         colNameString += funcColNames(table,typeTmp,namesTmp) + \
                          strBetweenTables
         structString += funcTableToStruct(table,typeTmp,namesTmp) + \
                         strBetweenTables
         insertString += funcTableToInsert(table,typeTmp,namesTmp) + \
                         strBetweenTables
         initStructString += funcInitStructs(table,typeTmp,namesTmp) + \
                             strBetweenTables
         selectString += funcSelect(table,typeTmp,namesTmp) + \
                         strBetweenTables
         convertString += funcConversions(table,typeTmp,namesTmp) + \
                          strBetweenTables
         handlerString += funcHandlers(table,typeTmp,namesTmp) + \
                          strBetweenTables
     globalDef = (
         "// Defined table names\n{:s}\n"+\
         "// Defined table field names\n{:s}\n"+\
         "// All Table function\n{:s}\n"+\
         "// Defined structures\n{:s}\n"+\
         "// Defined id structure\n{:s}\n"
         ).format(constString,fieldNameString,mTableString,structString,
         idTableString)
     globalFunc = (
         "// Defined insert functions\n{:s}\n"+\
         "// Initialization for structures\n{:s}\n"
         "// Conversion functions\n{:s}\n" + \
         "// Select functions\n{:s}\n"
         ).format(insertString,initStructString,
                  convertString,selectString)
     globalHandle = ("//Defined Handlers\n{:s}\n").format(handlerString)
     utilFuncs = ("//Column names and types\n{:s}\n").format(colNameString)
     toRet = fileContent(globalDef,globalFunc,globalHandle,utilFuncs)
     return toRet