//insert/update ObjectDeclaration public void UpdateObjDecl(ObjDecl theObj) { RefreshObjDeclID(theObj); DateTime Now = DateTime.Now; String _SQL; if (theObj.ID() > 0) { _SQL = "Update ObjectDecl Set ClassID='" + theObj.ClassID() + "',Function='" + theObj.Function() + "',Params='" + theObj.Params() + "',Returns='" + theObj.Returns() + "',ClassType=" + ((int)theObj.ClassType()).ToString() + " ,State=1" + " ,Descr='" + theObj.Description() + " ',Time=" + (Now.ToBinary().ToString()) + " ,Start=" + theObj.StartPos() + " ,Length=" + theObj.Length() + " where ID=" + (theObj.ID().ToString()); } else { _SQL = "INSERT INTO ObjectDecl (ClassID, Function, Params, Returns, ClassType, State, Time,Descr,Start,Length) VALUES('" + theObj.ClassID() + "', '" + theObj.Function() + "', '" + theObj.Params() + "', '" + theObj.Returns() + "', " + ((int)theObj.ClassType()).ToString() + ",1" + "," + (Now.ToBinary().ToString()) + ",'" + theObj.Description() + "'," + theObj.StartPos() + "," + theObj.Length() + ");"; } ExecuteSimpleQuery(_SQL); RefreshObjDeclID(theObj); //get Ids after insert }
//fetch the primary key for the dataset or set to invalid int RefreshObjDeclID(ObjDecl theObj) { String _SQL = ("SELECT ID from ObjectDecl where ClassID=='"); _SQL += theObj.ClassID() + "' AND Function='" + theObj.Function() + "';"; int Return = 0; Boolean Exists = false; try { SQLiteCommand command = new SQLiteCommand(_SQL, m_dbConnection); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { //Todo fix non exist Exists = true; Return = reader.GetInt32(reader.GetOrdinal("ID")); } reader.Dispose(); command.Dispose(); } catch (Exception e) { HandleDBError(e); } theObj.updateID(Return); return(Return); }