wip II
[sdk] / compiler / libec / src / dbpass.ec
index 3e93113..42dbff7 100644 (file)
@@ -271,6 +271,9 @@ static void ProcessExpression(Expression exp)
             ifDBStmt.compound.declarations->Add(MkDeclaration(MkListOne(MkSpecifierName("FieldIndex")), MkListOne(MkInitDeclarator(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("indexes")), 
                MkExpConstant(numIndexesString)), MkInitializerList(MkListOne(MkInitializerList(MkListOne(MkInitializerAssignment(MkExpIdentifier(MkIdentifier("null")))))))))));
             
+            // db.Begin();
+            ifDBStmt.compound.statements->Add(MkExpressionStmt(MkListOne(MkExpCall(MkExpMember(MkExpIdentifier(MkIdentifier("db")), MkIdentifier("Begin")), MkList()))));
+
             ifDBStmt.compound.statements->Add(compound = MkCompoundStmt(null, tableStatements));
             compound.compound.context = Context { parent = ifDBStmt.compound.context };
             /*
@@ -285,6 +288,9 @@ static void ProcessExpression(Expression exp)
             ifDBStmt.compound.statements->Add(compound = MkCompoundStmt(null, indexStatements));
             compound.compound.context = Context { parent = ifDBStmt.compound.context };
 
+            // db.Commit();
+            ifDBStmt.compound.statements->Add(MkExpressionStmt(MkListOne(MkExpCall(MkExpMember(MkExpIdentifier(MkIdentifier("db")), MkIdentifier("Commit")), MkList()))));
+
             // TODO: Don't make use of extension
             exp.type = extensionCompoundExp;
             exp.compound = databaseOpenStmt;
@@ -684,6 +690,8 @@ static void ProcessClass(ClassDefinition _class)
    }
 }
 
+static int curSymbolID = 0;
+
 static void ProcessDBTable(DBTableDef table)
 {
    OldList * rowClassDefs = MkList(), * idClassDefs = null;
@@ -695,7 +703,7 @@ static void ProcessDBTable(DBTableDef table)
    char nameField[1024];
    OldList * args;
    OldList * members;
-   int symbolID = 0; //MAXINT; //globalContext.nextID++;
+   int symbolID = curSymbolID; //MAXINT; //globalContext.nextID++;
    if(table.symbol)
       idClassDefs = MkList();
 
@@ -1135,6 +1143,9 @@ public void ProcessDBTableDefinitions()
       for(external = ast->first; external; external = external.next)
       {
          curExternal = external;
+
+         if(external.symbol) curSymbolID = external.symbol.idCode;
+         addAfter = external.prev;
          switch(external.type)
          {
             case dbtableExternal:
@@ -1146,6 +1157,10 @@ public void ProcessDBTableDefinitions()
       for(external = ast->first; external; external = external.next)
       {
          curExternal = external;
+
+         if(external.symbol) curSymbolID = external.symbol.idCode;
+         addAfter = external.prev;
+
          switch(external.type)
          {
             case functionExternal: