Exemple #1
0
 def __init__(self,dbaseName,srcName, srcType=' TABLE ',conn=None):
     '''
     A pydset instance is initialized over an existing table in SQLITE file.
     '''
     try:
         self.dbaseName = dbaseName;
         if conn == None:
             self.pConn = sqlite3.connect(dbaseName)
         else: self.pConn = conn
         self.srcName = srcName.strip()
         self.srcType = srcType.strip()
         self.colNames = []
         self.colTypes = {}
         self.persist = True
         query = 'PRAGMA table_info('+self.srcName+')'
         colDetails = self.pConn.cursor().execute(query)
         numrows = 0
         for colDetail in colDetails:
             colName,g = clean_text(colDetail[1])
             colType = clean_string(colDetail[2])
             self.colNames.append(colName) 
             self.colTypes[colName]=colType
             numrows = numrows+1
         if numrows == 0:
             raise ValueError("ERROR: Can't find table "
                              +srcName+" in database "+dbaseName)
     except Exception as err:
         print_error(err,'pydset.__init__')
Exemple #2
0
    def check_temporicity(self, colName, dateFormat='yyyy-mm-dd'):        
        try:
#             if self.colTypes[colName]!='VARCHAR':
#                 raise ValueError("pydset.check_numericity: Operation permitted for text columns only.")
            matcher = {'dd-mm-yyyy':'\d{1,2}-\d{1,2}-\d{4}','yyyy-mm-dd':'\d{4}-\d{1,2}-\d{1,2}'}
            isDate = True           
            results = self.get(colName)               
            for value in results:
                val = clean_string(str(value),replaceHyphen=False)
                isDate = isDate and (re.match(matcher[dateFormat],val)!=None)
            return isDate        
        except Exception as err:
            print (err)
            print_error(err,'dataset.check_temporicity')  
Exemple #3
0
    def check_numericity(self, colName):
        def make_unicode(input):
            if type(input) != unicode:
                input =  input.decode('utf-8')
                return input
            else:
                return input
        try:
#            if ('VARCHAR'.lower() != self.colTypes[colName].lower().strip()):
#                 raise ValueError("pydset.check_numericity: Operation permitted for text columns only.")
            results = self.get(colName)
            isNumber = True
            colVals  = []
            for value in results:
                val = clean_string(str(value),replaceHyphen= False)
                uv = make_unicode(val)
                isNumber = isNumber and (uv.isdecimal() or uv.isnumeric())
            return isNumber 
        except Exception as err:
            print_error(err, 'pydset.check_numericity')