Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Seeking a brilliant idea to replace NextID() function
Message
From
21/01/2008 12:10:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
MS SQL Server
Miscellaneous
Thread ID:
01283680
Message ID:
01283713
Views:
19
>>I checked, probably brain dead now, can't see how it helps to know the key before inserting a new record.
>>Cetin
>
>It works for me for my business class. I use ODBC for SQL Server and manual transactions.
>
>DO CASE
>   CASE oApp.oVar.DBTYPE = DBTYPE_NATIVE
>        BEGIN TRANSACTION
>   CASE oApp.oVar.DBTYPE = DBTYPE_SQL
>        SQLSETPROP(oApp.oVar.sqlHandler,"Transactions",DB_TRANSMANUAL)
>        IF SQLEXEC(oApp.oVar.sqlHandler,[BEGIN TRANSACTION]) < 0
>           ASSERT .f.
>        ENDIF
>ENDCASE
>
>IF this.Isnewrecord  && If We need to Insert new record in parent table.
>   ** Update the Parent table, so we get ID back
>   IF this.Persons.Updatetable() && Just a method similar to TableUpdate() function with Error handling in it.
>      lnId       = EVAL(this.Persons.Alias+[.Id])
>      m.lnRetVal = This.UpdateCursors(lnId) && Update all child tables, here I call Updatetable() method for every CA I have in that Class
>   ENDIF
>ELSE
>   m.lnRetVal = This.UpdateCursors() && Update all tables
>ENDIF
>
>IF m.lnRetVal
>   DO CASE
>      CASE oApp.oVar.DBTYPE = DBTYPE_NATIVE
>           END TRANSACTION
>      CASE oApp.oVar.DBTYPE = DBTYPE_SQL
>           SQLEXEC(oApp.oVar.sqlhandler,[COMMIT TRANSACTION])
>           SQLSETPROP(oApp.oVar.sqlHandler,"Transactions",DB_TRANSAUTO)
>   ENDCASE
>   IF this.lnrabid # crsPersons.Id
>      this.lnrabid     = crsPersons.Id
>   ENDIF
>   this.Isnewrecord = .f.
>ELSE
>   DO CASE
>      CASE oApp.oVar.DBTYPE = DBTYPE_NATIVE
>           ROLLBACK
>      CASE oApp.oVar.DBTYPE = DBTYPE_SQL
>           SQLEXEC(oApp.oVar.sqlhandler,[ROLLBACK TRANSACTION])
>           SQLSETPROP(oApp.oVar.sqlHandler,"Transactions",DB_TRANSAUTO)
>   ENDCASE
>ENDIF
>
>RETURN m.lnRetVal
>
Borislav,
Stealing your code (be informed) for other parts of this and will modify to suit my needs:)
Probably I couldn't explain my need well. I don't want to check and update child tables too. Mostly because it's too much work and perfromance would suffer. I simply want to know the key before insertion and submit as updatable to backend, or let backend assign one when I don't supply.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform