• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

example for slRunProc?

Started by Bern Ertl, December 15, 2008, 05:01:44 PM

Previous topic - Next topic

Bern Ertl

I see the Entry1 and Entry2 functions declared in SQLiteningProcsA.BAS.  I also see the description for slRunProc defined in SQLitening.txt.

Im not sure I am understanding the explaination though.  Any chance someone could post a small sample showing how to call Entry1?


Fred Meier

This sample will run the StoreOrder proc four times, storing four orders.

The following runs on the client.
#Compile Exe
#Dim All
#Include "SQLitening.Inc"

'==============================<[ Main ]>==============================
Function PbMain()

   Local lsItems as String

   slConnect "LocalHost"
   slOpen "Test.Sld", "C"
   slExe "Drop Table if exists Orders"
   slExe "Create Table Orders (Company)"
   slExe "Drop Table if exists Items"
   slExe "Create Table Items ([Order], Quantity, Product)"

   lsItems = "10,Knives|" & _
             "10,Forks|" & _
             "10,Spoons|" & _
             "10,Plates|" & _
             "10,Cups"

   slRunProc "KStoreOrder", 0, 0, "Action Hardware", lsItems         ' Store order 1
   slRunProc "KStoreOrder", 0, 0, "Mickeys Hardware", lsItems        ' Store order 2
   slRunProc "KStoreOrder", 0, 0, "Joes Goods", lsItems              ' Store order 3
   slRunProc "KStoreOrder", 0, 0, "Another Store", lsItems           ' Store order 4

End Function


The following runs on the server.
#Compile Dll
#Dim All

'=========================<[ SQLite Declares ]>=========================
Declare Function sqlite3_exec cdecl lib "sqlite3.dll" alias "sqlite3_exec" (byval rhDab as Dword, byval rspStatements as Dword, byval rhZero as Dword, byval rhZero as Dword, byval rhZero as Dword) as Long
Declare Function sqlite3_last_insert_rowid cdecl lib "sqlite3.dll" alias "sqlite3_last_insert_rowid" (byval rhDab as Dword) as Quad

'=============================<[ Macros ]>=============================
' ==========>>> Exe
macro function slmExe(rhDab, rsStatement)
   macrotemp lsA
   Local lsA as String
   lsA = rsStatement
end macro = sqlite3_exec(rhDab, strptr(lsA), 0, 0, 0)

' ==========>>> Get Insert ID
macro function slmGetInsertID(rhDab)
end macro = sqlite3_last_insert_rowid (rhDab)

'==========================<[ Store Order ]>===========================
Function StoreOrder alias "StoreOrder" (byval rhDab as Dword, _
                                byval rlTcpFileNumber as Long, _
                                blParm1 as Long, _
                                blParm2 as Long, _
                                bsParm3 as String, _
                                bsParm4 as String)Export as Long

   Local llDo as Long
   Local llRC as Long
   Local lsOrder as String
   Local lsItem as String

   llRC = slmExe(rhDab, "Begin")
   if llRC then goto ExitRut

   llRC = slmExe(rhDab, "Insert into Orders values('" & bsParm3 & "')")
   if llRC then goto ExitRut

   lsOrder = format$(slmGetInsertID(rhDab))
   for llDo = 1 to parsecount(bsParm4, "|")
      lsItem = parse$(bsParm4, "|", llDo)
      llRC = slmExe(rhDab, "Insert into Items values(" & lsOrder & "," & parse$(lsItem, 1) & ",'" & parse$(lsItem, 2) & "')")
      if llRC then goto ExitRut
   next

   llRC = slmExe(rhDab, "End")
   if llRC then goto ExitRut

   ExitRut:
   function = llRC

End Function



Bern Ertl

Thanks Fred.  I had to stare at it a bit, but I get it now.  A couple of questions though...

- Your sample code includes a rlTcpFileNumber parameter in the StoreOrder declaration.  The Entry1 sample function in the SQLiteningProcsA.BAS function did not include that parameter.  Is this a new addition per the modifications you made recently to accomodate handling the management of a user log-in system for me?

- I see that any data I want to return from a function will need to be passed via one or more of the four required user defined parameters.  Your sample functions (called by slRunProc) appear to be returning an llRC return code.  What is slRunProc expecting for return values?

Fred Meier

Bern
Your are right, the rlTcpFileNumber is not in version 1.10, my mistake for including it in this sample.  It will be in version 1.11 and is in the changes I emailed you for testing (when you say OK I will release 1.11).  For anybody else who wants to try this sample just remove that parm.

Right again, slRunProc expects the SQLitening standard return values (0=OK, <>0=Error) so any data a proc needs to return must be passed in any or all of the four read/write parms.

Bern Ertl

Quote from: Fred Meier on December 16, 2008, 01:34:30 PM(when you say OK I will release 1.11)

I'm diving in head first into the pool.  As soon as I've figured out how to swim, I should be able to tell you how deep the water is.  :)