SQLitening Support Forum

Support Forums => READ THIS BEFORE REGISTERING FOR THIS FORUM => Topic started by: Rankin on July 26, 2016, 01:16:14 PM

Title: Just posting as I was asked to do!
Post by: Rankin on July 26, 2016, 01:16:14 PM
I am hoping to be able to use SQLitening on my applications along with Sqlite for Multi-User database access.  I'm going to take a look around the forums and hopefully find some useful information for implementation.

I use Omnis Studio 8, running Windows 10.  I will be migrating old native procedural DML to OOP techniques to a SQL compliant database server.  Hopefully Sqlite.  We are a very small IT department within a Non-Profit Organisation. 
Title: Re: Just posting as I was asked to do!
Post by: cj on July 26, 2016, 03:47:02 PM
This is more complicated than most need since it passes a UDT and is multithreaded
Not to scare anyone away.

#DIM ALL
#INCLUDE ONCE "win32api.inc"
#INCLUDE ONCE "\sql\bin\sqlitening.inc"
GLOBAL gs AS STRING

TYPE sql_udt
  server    AS STRING * 64
  port      AS LONG
  database  AS STRING * 64
  sql       AS STRING * 512
  hEventReady AS LONG 'assure everything allocated/started
END TYPE

FUNCTION PBMAIN () AS LONG
  LOCAL u AS sql_udt, ThreadNumber,ThreadsWanted AS LONG
  ThreadsWanted = 2
  DIM hThread(1 TO ThreadsWanted) AS LONG
  FOR ThreadNumber = 1 TO ThreadsWanted
    u.server   = ""     'change if using server
    u.port     = 51234  'change if using server
    u.database = "sample.db3"
    u.sql      = "select count(*) from parts"
    u.hEventReady     = CreateEvent (BYVAL 0, BYVAL %TRUE, BYVAL %FALSE, BYVAL 0)
    THREAD CREATE send_email_thread (BYVAL VARPTR(u)) TO hThread(ThreadNumber)
    WaitForSingleObject u.hEventReady,%INFINITE
    CloseHandle u.hEventReady
  NEXT
  WaitForMultipleObjects ThreadsWanted, hThread(1),%TRUE, %INFINITE
  FOR ThreadNumber = 1 TO ThreadsWanted
    THREAD CLOSE hThread(ThreadNumber)  TO hThread(ThreadNumber)
  NEXT
  ? gs,, "All results"
  '10000
  '10000
END FUNCTION

THREAD FUNCTION send_email_thread(BYVAL u AS sql_UDT PTR) AS LONG
  ThreadSafeHelper u
END FUNCTION

FUNCTION ThreadSafeHelper(BYVAL u AS sql_udt PTR) THREADSAFE AS LONG
  LOCAL sHost,sDatabase,sql AS STRING, PortNumber AS LONG
  LOCAL sResultArray() AS STRING
  sHost = RTRIM$(@u.server)
  PortNumber = @u.port
  sDataBase = RTRIM$(@u.database)
  sql = RTRIM$(@u.sql)
  SetEvent @u.hEventReady 'everything now allocated
  'connect using server is a host name is passed
  IF LEN(sHost) THEN slConnect(sHost,PortNumber)
  slOpen(sDatabase,"C") 'C = create if not exists
  slSelAry sql,sResultArray(),"c" 'c=don't include column names
  IF LEN(sHost) THEN slDisconnect
  gs+= JOIN$(sResultArray(),$CR) + $CR 'put array into a string
END FUNCTION
Title: Re: Just posting as I was asked to do!
Post by: cj on July 26, 2016, 03:57:25 PM
#INCLUDE ONCE "sqlitening.inc"
$Host = "192.168.1.2"
%PortNumber = 51234
$DataBase   = "sample.db3"
$Sql        = "select count(*) from parts"
%UseServer  = 1

FUNCTION PBMAIN () AS LONG
  LOCAL sResultArray() AS STRING
  IF %UseServer THEN slConnect $Host,%PortNumber
  slOpen $Database,"C"
  slSelAry $Sql,sResultArray(),"c"
  IF %UseServer THEN slDisconnect
  ? JOIN$(sResultArray(),$CR),,"Result" '10000
END FUNCTION