コード例 #1
0
def BuildTables(database_namespace):
    TableA = Table(database_namespace, "Table2A")
    TableA.AddCol("PKcol_TabA")
    TableA.AddCol("Data_Column")
    TableA.AddPK("PKcol_TabA")
    if TableA.VerifyFKrefsCompletePK(
    ):  # In SQL mode, this will create the table
        if _DB_mode == "AS":
            print(TableA.TableName,
                  "has complete FK to PK references (or none exist in table)")
        else:
            print(TableA.TableName, "has been created in the SQL database")

    TableB = Table(database_namespace, "Table2B")
    TableB.AddCol("PKcol_TabB")
    TableB.AddCol("FK_BtoA")
    TableB.AddCol("Data_Column")
    TableB.AddPK("PKcol_TabB")
    TableB.AddPK(
        "FK_BtoA"
    )  # *** This is the only difference between Schema 1 and Schema 2
    TableB.AddFK("FK_BtoA", "Table2A", "PKcol_TabA")
    if TableB.VerifyFKrefsCompletePK():
        if _DB_mode == "AS":
            print(TableB.TableName,
                  "has complete FK to PK references (or none exist in table)")
        else:
            print(TableB.TableName, "has been created in the SQL database")
コード例 #2
0
def BuildTables(
    database_namespace
):  # TODO Verify this is the schema we want. Noticed old DB name was SEF and not SQL like the others
    TableA = Table(database_namespace, "Table3A")
    TableA.AddCol("PKcol_TabA")
    TableA.AddCol("DataColA")
    TableA.AddPK("PKcol_TabA")
    if TableA.VerifyFKrefsCompletePK(
    ):  # In SQL mode, this will create the table
        if _DB_mode == "AS":
            print(TableA.TableName,
                  "has complete FK to PK references (or none exist in table)")
        else:
            print(TableA.TableName, "has been created in the SQL database")

    TableB = Table(database_namespace, "Table3B")
    TableB.AddCol("PKcol_TabB")
    TableB.AddCol("DataColB")
    TableB.AddPK("PKcol_TabB")
    if TableB.VerifyFKrefsCompletePK():
        if _DB_mode == "AS":
            print(TableB.TableName,
                  "has complete FK to PK references (or none exist in table)")
        else:
            print(TableB.TableName, "has been created in the SQL database")

    TableC = Table(database_namespace, "Table3C")
    TableC.AddCol("FK_CtoA")
    TableC.AddCol("FK_CtoB")
    TableC.AddCol("PKcol_TabC")
    TableC.AddCol("DataColC")
    TableC.AddPK("FK_CtoA")
    TableC.AddPK("FK_CtoB")
    TableC.AddPK("PKcol_TabC")
    TableC.AddFK("FK_CtoA", "Table3A", "PKcol_TabA")
    TableC.AddFK("FK_CtoB", "Table3B", "PKcol_TabB")
    if TableC.VerifyFKrefsCompletePK():
        if _DB_mode == "AS":
            print(TableC.TableName,
                  "has complete FK to PK references (or none exist in table)")
        else:
            print(TableC.TableName, "has been created in the SQL database")
コード例 #3
0
TableA.Insert([1, "datadata"])
TableA.Insert([2, "datadata"]) 
TableA.Insert([3, "datadata"]) 
TableB.Insert([1, 1, "datadata"])
TableB.Insert([1, 2, "datadata"]) # This should work
print(">>> Test 2: Expect an Insert Failed error, non-unique composite PK")
TableB.Insert([1, 1, "datadata"]) # This should fail, repeated PK

# Test 4a: (How many records are removed)
# At this point, should have 7 records. 3 in Table 2A, 2 in Table 2B, 2 the Table 1B's FK Table
print(">>> Test 4a: Expect 7 records removed")
Table.RemoveAllTables(client, True) #True to wait for confirmation

# Test 5: FK does not reference a complete PK
TableA = Table(database, "Table4A")
TableA.AddCol("PKcol1")
TableA.AddCol("PKcol2")
TableA.AddCol("Data_Column")
TableA.AddPK("PKcol1")
TableA.AddPK("PKcol2")
if TableA.VerifyFKrefsCompletePK(): # This should pass
    if _DB_mode == "AS":
        print(TableA.TableName, "has complete FK to PK references (or none exist in table)")
    else:
        print(TableA.TableName, "has been created in the SQL database")

TableB = Table(database, "Table4B")
TableB.AddCol("PKcol1")
TableB.AddCol("FK1_BtoA")
TableB.AddCol("FK2_BtoA")
TableB.AddCol("Data_Column")