Ejemplo n.º 1
0
 def __init__(self, is_new, tbl_mgr: TableMgr, tx: Transaction):
     self._tbl_mgr = tbl_mgr
     if is_new:
         sch = Schema()
         sch.add_string_field("viewname", TableMgr.MAX_NAME)
         sch.add_string_field("viewdef", self.MAX_VIEWDEF)
         tbl_mgr.create_table("viewcat", sch, tx)
Ejemplo n.º 2
0
    def __init__(self, is_new, tx):
        """
        Creates a new catalog manager for the database system.
        If the database is new, then the two catalog tables
        are created.
        :param is_new: has the value true if the database is new
        :param tx: the startup transaction
        """
        assert isinstance(tx, Transaction)
        tcat_schema = Schema()
        tcat_schema.add_string_field("tblname", self.MAX_NAME)
        tcat_schema.add_int_field("reclength")
        self._tcat_info = TableInfo("tblcat", tcat_schema)

        fcat_schema = Schema()
        fcat_schema.add_string_field("tblname", self.MAX_NAME)
        fcat_schema.add_string_field("fldname", self.MAX_NAME)
        fcat_schema.add_int_field("type")
        fcat_schema.add_int_field("length")
        fcat_schema.add_int_field("offset")
        self._fcat_info = TableInfo("fldcat", fcat_schema)

        if is_new:
            self.create_table("tblcat", tcat_schema, tx)
            self.create_table("fldcat", fcat_schema, tx)
Ejemplo n.º 3
0
 def __init__(self, is_new, tbl_mgr: TableMgr, tx: Transaction):
     self._tbl_mgr = tbl_mgr
     if is_new:
         sch = Schema()
         sch.add_string_field("viewname", TableMgr.MAX_NAME)
         sch.add_string_field("viewdef", self.MAX_VIEWDEF)
         tbl_mgr.create_table("viewcat", sch, tx)
Ejemplo n.º 4
0
    def __init__(self, is_new, tx):
        """
        Creates a new catalog manager for the database system.
        If the database is new, then the two catalog tables
        are created.
        :param is_new: has the value true if the database is new
        :param tx: the startup transaction
        """
        assert isinstance(tx, Transaction)
        tcat_schema = Schema()
        tcat_schema.add_string_field("tblname", self.MAX_NAME)
        tcat_schema.add_int_field("reclength")
        self._tcat_info = TableInfo("tblcat", tcat_schema)

        fcat_schema = Schema()
        fcat_schema.add_string_field("tblname", self.MAX_NAME)
        fcat_schema.add_string_field("fldname", self.MAX_NAME)
        fcat_schema.add_int_field("type")
        fcat_schema.add_int_field("length")
        fcat_schema.add_int_field("offset")
        self._fcat_info = TableInfo("fldcat", fcat_schema)

        if is_new:
            self.create_table("tblcat", tcat_schema, tx)
            self.create_table("fldcat", fcat_schema, tx)
Ejemplo n.º 5
0
 def __field_type(self, fldname: str) -> Schema:
     schema = Schema()
     if self._lex.match_keyword("int"):
         self._lex.eat_keyword("int")
         schema.add_int_field(fldname)
     else:
         self._lex.eat_keyword("varchar")
         self._lex.eat_delim("(")
         str_len = self._lex.eat_int_constant()
         self._lex.eat_delim(")")
         schema.add_string_field(fldname, str_len)
     return schema
Ejemplo n.º 6
0
 def __field_type(self, fldname: str) -> Schema:
     schema = Schema()
     if self._lex.match_keyword("int"):
         self._lex.eat_keyword("int")
         schema.add_int_field(fldname)
     else:
         self._lex.eat_keyword("varchar")
         self._lex.eat_delim("(")
         str_len = self._lex.eat_int_constant()
         self._lex.eat_delim(")")
         schema.add_string_field(fldname, str_len)
     return schema
Ejemplo n.º 7
0
 def __init__(self, is_new, tblmgr, tx):
     """
     Creates the index manager.
     This constructor is called during system startup.
     If the database is new, then the idxcat table is created.
     :param is_new: indicates whether this is a new database
     :param tx: the system startup transaction
     """
     assert isinstance(tblmgr, TableMgr)
     assert isinstance(tx, Transaction)
     if is_new:
         sch = Schema()
         sch.add_string_field("indexname", TableMgr.MAX_NAME)
         sch.add_string_field("tablename", TableMgr.MAX_NAME)
         sch.add_string_field("fieldname", TableMgr.MAX_NAME)
         tblmgr.create_table("idxcat", sch, tx)
     self._ti = tblmgr.get_table_info("idxcat", tx)
Ejemplo n.º 8
0
 def __init__(self, is_new, tblmgr, tx):
     """
     Creates the index manager.
     This constructor is called during system startup.
     If the database is new, then the idxcat table is created.
     :param is_new: indicates whether this is a new database
     :param tx: the system startup transaction
     """
     assert isinstance(tblmgr, TableMgr)
     assert isinstance(tx, Transaction)
     if is_new:
         sch = Schema()
         sch.add_string_field("indexname", TableMgr.MAX_NAME)
         sch.add_string_field("tablename", TableMgr.MAX_NAME)
         sch.add_string_field("fieldname", TableMgr.MAX_NAME)
         tblmgr.create_table("idxcat", sch, tx)
     self._ti = tblmgr.get_table_info("idxcat", tx)
Ejemplo n.º 9
0
 def __schema(self) -> Schema:
     """
     Returns the schema of the index records.
     The schema consists of the dataRID (which is
     represented as two integers, the block number and the
     record ID) and the dataval (which is the indexed field).
     Schema information about the indexed field is obtained
     via the table's metadata.
     :return the schema of the index records
     """
     sch = Schema()
     sch.add_int_field("block")
     sch.add_int_field("id")
     if self._ti.schema().type(self._fldname) == INTEGER:
         sch.add_int_field("dataval")
     else:
         fldlen = self._ti.schema().length(self._fldname)
         sch.add_string_field("dataval", fldlen)
Ejemplo n.º 10
0
 def __schema(self) -> Schema:
     """
     Returns the schema of the index records.
     The schema consists of the dataRID (which is
     represented as two integers, the block number and the
     record ID) and the dataval (which is the indexed field).
     Schema information about the indexed field is obtained
     via the table's metadata.
     :return the schema of the index records
     """
     sch = Schema()
     sch.add_int_field("block")
     sch.add_int_field("id")
     if self._ti.schema().type(self._fldname) == INTEGER:
         sch.add_int_field("dataval")
     else:
         fldlen = self._ti.schema().length(self._fldname)
         sch.add_string_field("dataval", fldlen)