Exemple #1
0
 def test_initialize(self):
     """ Tests that AdvancedTable can be properly initialized """
     testtable = Table.AdvancedTable(utils.TESTTABLESQL,self.connection)
     ## Make sure it's actually an AdvancedTable
     self.assertIsInstance(testtable,Table.AdvancedTable)
     ## Make sure it's attributes are correct
     self.assertEqual(testtable._definition,utils.TESTTABLESQL)
     self.assertEqual(testtable.database,self.connection)
     ## Should be Equal (at the moment) to a normal Table
     self.assertEqual(testtable,self.connection.gettable("testtable"))
Exemple #2
0
    def gettablebyid(self,rowid):
        """ Returns a Table Object representing the table with the given rowid.

        rowid should be an integer which represents the table's rowid in the sqlite_master table.
        Raises a ValueError if the table does not exist.
        """
        if not isinstance(rowid,int):
            raise TypeError("rowid should be an integer")
        with Utilities.temp_row_factory(self,objects.dict_factory):
            tableentry = self.execute("""SELECT sql FROM sqlite_master WHERE type="table" AND rowid=?;""",(rowid,)).fetchone()
        if not tableentry:
            raise ValueError(f"Table {tablename} does not exist.")

        if self.parser: return self.parser(tableentry['sql'],database = self).obj.to_advancedtable()
        return Table.AdvancedTable(tableentry['sql'],database = self)
Exemple #3
0
 def getalltables(self, advanced=True):
     """ Returns all tables in the database as Table Objects.
         
         If advanced is True (default), returns Advanced Objects when possible.
     """
     tables = self.execute("""SELECT sql FROM sqlite_master WHERE type="table";""").fetchall()
     ## Let parser determine type (if available)
     if self.parser:
        tables = [self.parser(table['sql']).obj for table in tables]
        tables = [table.to_advancedtable(self) if hasattr(table,'to_advancedtable') else table for table in tables]
     else:
         if advanced:
             tables = [Table.AdvancedTable(table['sql'],self) for table in tables]
         else:
             tables = [Table.Table(table['sql'],self) for table in tables]
     return tables