Posts

Showing posts with the label save

Parent Child Table (part 4)

 Welcome back! Continuing on with the Save Procedure.  In order for the children to be linked to their Parent, the Parent MUST be saved prior to the children.  So, lets focus in on the bottom end of the SQL INSERT: PassFail = DB::Update(DBID, Sql$) If PassFail *Class\State = DB::#Clean *Class\ID = DB::getLastID(DBID, "Galaxy") EndIf DB::Close(DBID) ;----------------------------------------------- SaveSolarSystemCollection(*Class) ;----------------------------------------------- As you can see once we close the database and retrieve the Parent's ID from the database, we then call the Save Children Procedure.  On the SQL UPDATE, we are free to call the Child Save Procedure immediately after the Close Procedure. PassFail = DB::Update(DBID, Sql$) If PassFail *Class\State = DB::#Clean EndIf DB::Close(DBID) ;--------------------...

Parent Child Table (Part 3)

 Moving on to the Find Methods.  Here again we have some changes. After we load up our Parent Record, we then need to load up its children.  I'll focus in on the in the code segment below: PassFail = DB::Query(DBID, Sql$) If PassFail While NextDatabaseRow(DBID) With *Class \ID = GetDatabaseLong(DBID, DatabaseColumnIndex(DBID,"ID")) \Name = GetDatabaseString(DBID, DatabaseColumnIndex(DBID,"Name")) \State = DB::#Clean EndWith Wend EndIf DB::Close(DBID) ClearList(*Class\SolarSystemCollection.SOLARSYSTEM::SolarSystem()) ;----------------------------------------------- LoadSolarSystemCollection(*Class) ;----------------------------------------------- ProcedureReturn PassFail Here you can see After the Parent Record is loaded, and the database Closed, we then Clear the List in preparation for loading it, then we call a new Procedure to Load the Child Collection. ...

Single or stand-alone table (part 6)

  Now we are getting to the true meat of the Module! Though SQL separates the Insertion from the Update, I feel it is NOT the Form code's responsibility to make this decision. The Goal is to remove this from the Form and put this decision into the Data Layer. Therefore, these two are combined into a single and simple Save Method. The steps necessary to Insert and Update are the same, combining the is the only way to not have redundant code. in pseudo code the steps are pretty straight forward: If Validate Data = TRUE     IF New, then Insert         Update Data ID, set to Clean     ELSE Update         Set to Clean ELSE Sent Error Message(s) Let's take a Look at the Save Method, and then I'll walk you through it. Procedure.i Save(*Class.FighterSize) Protected Sql$, Result, DBID, Length, *MemoryGraphicID Protected PassFail = #False If Validate(*Class) = #False ProcedureReturn #False Else ...