Beispiel #1
0
 def __init__(self, *args, **kwargs):
     self.tableName = None
     self.fieldName = None
     self.sqlfile = None
     self.saveAs = 'str'
     self.loadAs = 'str'
     pout.b(self.loadAs)
Beispiel #2
0
    def DescribeTable(self):
        if self.dbtype == 'mysql':
            query = '''SELECT * FROM information_schema.COLUMNS 
                    WHERE TABLE_SCHEMA = 'rhp' 
                    AND TABLE_NAME = "{}"
                    AND COLUMN_NAME = "{}"'''.format(self.table)
        if self.dbtype == 'sqlite3':
            query = '.schema {}'.format(self.table)

        data = []
        returnd = DBConnect(query, data, sql_file=self.sql_file).ALL()
        pout.b(f'DescribeTable : {query} \nReturnd : {returnd}')
        info = {}
        tb = len(returnd)
        for cnt in range(0, tb):
            for val in returnd:
                pout.v(f'Val : {val}')
                info[cnt] = {
                    'field': val[2],
                    'type': val[7],
                    'null': val[6],
                    'key': val[16],
                    'default': val[5],
                    'extra': val[17]
                }
            returnd = info
        pout.v(returnd)
        time.sleep(3)
        # except:
        # returnd = None

        return returnd
Beispiel #3
0
    def ONE(self):
        if self.dbtype == 'mysql':
            con = pymysql.connect(host='localhost',
                                  user='******',
                                  passwd='password',
                                  db='rhp')
        if self.dbtype == 'fdb':
            con = fdb.connect(host='localhost',
                              database=f'{self.sql_file}',
                              user='******',
                              password='******')
        if self.dbtype == 'sqlite3':
            pout.v(self.sql_file)
            con = sqlite3.connect(self.sql_file)
            # con.row_factory = sqlite3.Row

        cur = con.cursor()
        if len(self.data) > 0:
            cur.execute(self.query, self.data)
        else:
            cur.execute(self.query)

        returnd = cur.fetchone()
        pout.v(returnd)
        #print(returnd[0])
        pout.b('--')
        # if self.dbtype == 'sqlite3':
        #     returnd = [{k: item[k] for k in item.keys()} for item in returnd]

        if re.search('(UPDATE|INSERT)', self.query, re.I):
            con.commit()

        con.close()

        return returnd
Beispiel #4
0
    def test_variable(self):
        s = "foo"
        with testdata.capture() as c:
            pout.b(s)
        self.assertTrue("foo" in c)

        s = b"foo"
        with testdata.capture() as c:
            pout.b(s)
        self.assertTrue("foo" in c)
Beispiel #5
0
 def OnSave(self, whereField, whereValue):
     setTo = self.GetPath()
     pout.b(f'WhereField : {whereField} --> WhereValue : {whereValue}')
     pout.v(f'tableName : {self.tableName} ; fieldName : {self.fieldName}')
     try:
         item = LookupDB(self.tableName).UpdateSingle(
             self.fieldName, setTo, whereField, whereValue)
     except:
         pout.v(
             f'Table : {self.tableName} ; Field : {self.fieldName} ; WhereField : {whereField} ; whereValue: {whereValue}'
         )
Beispiel #6
0
    def test_b(self):
        with testdata.capture() as c:
            pout.b()
        self.assertTrue("*" in c)

        with testdata.capture() as c:
            pout.b(5)
        self.assertTrue("*" in c)

        with testdata.capture() as c:
            pout.b('this is the title')
        self.assertTrue("* this is the title *" in c)

        with testdata.capture() as c:
            pout.b('this is the title 2', 5)
        self.assertTrue("* this is the title 2 *" in c)

        with testdata.capture() as c:
            pout.b('this is the title 3', 3, '=')
        self.assertTrue("= this is the title 3 =" in c)
Beispiel #7
0
    def __call__(self, *args, **kwargs):
        """call is used when there are (...) on the decorator"""
        pout.v("__call__", args, kwargs)
        #pout.v(vars(self))
        #frame = inspect.currentframe()
        #frames = inspect.getouterframes(frame)
        #pout.v(frames[1:])

        def wrapper(*args, **kwargs):
            return "__call__"
        return wrapper


# the first state is decorated with no params
pout.b("@Dec")
@Dec
def foo(*args, **kwargs): pass
pout.v("defined")
foo("func1", "func2")


# problem here is this is indistinguishable from @Dec
pout.b("@Dec(callback)")
def callback(*args, **kwargs): pass
@Dec(callback)
def foo(*args, **kwargs): pass
pout.v("defined")
foo("func1", "func2")

pout.b(5)