• Welcome, Guest. Please login.
 
April 18, 2019, 10:14:36 am

News:

Welcome to the SQLitening support forums!


Introduction

Started by dbinev, August 12, 2016, 11:18:52 am

Previous topic - Next topic

dbinev

Hi there,

I am exploring options to utilizing SQLite in several scenarios, including shared DB access.
Unfortunately, I am not familiar with PowerBASIC, but I hope I can get some inspiration from your work, guys...

cj

SQLitening is great.  Hope you like it.

#INCLUDE "sqlitening.inc"
FUNCTION PBMAIN AS LONG 'simple.bas
  LOCAL sql,sresult AS STRING
  slconnect "45.40.133.16",51234
  slopen "sample.db3"+$BS+ "%" ,"R"
  sql = "select count(*) from parts"
  sresult = GetRecordSet(sql)
  IF LEN(sresult) THEN ? sresult,%MB_SYSTEMMODAL
  slDisconnect
END FUNCTION

FUNCTION GetRecordSet(SqlStatement AS STRING) AS STRING
  DIM sArray() AS STRING
  slselary SqlStatement,sArray(),"Q9c"
  IF UBOUND(sArray) > -1 THEN FUNCTION = JOIN$(sArray(),$CR)
END FUNCTION

cj

Demo using 2-dimensional recordset

#DIM ALL
#INCLUDE "sqlitening.inc"

%UseServer = 1  'Optionally connect to CJ server

FUNCTION PBMAIN AS LONG 'simple.bas
  LOCAL sHost AS STRING
  LOCAL COL,ROW,cols,rows,PortNumber AS LONG
  LOCAL sDatabase,s          AS STRING
  LOCAL sColumnNames()       AS STRING
  LOCAL lowcol               AS LONG
  LOCAL lowrow               AS LONG
  LOCAL highcol              AS LONG
  LOCAL highrow              AS LONG
'-------------------------------------------------------
  sHost = "45.40.133.16"
  PortNumber = 51234
  IF %UseServer THEN slconnect sHost,PortNumber:BEEP
'-------------------------------------------------------
  sDataBase = "sample.db3"
  slopen sDatabase + $BS + "%","R"
'-------------------------------------------------------
  REDIM sArray(0) AS STRING
  slSelAry "select rowid,manuf,redref from parts limit 5",sArray()
'-------------------------------------------------------
  lowcol    = LBOUND(sArray,1)
  lowrow    = LBOUND(sArray,2)
  highcol   = UBOUND(sArray,1)
  highrow   = UBOUND(sArray,2)
  FOR ROW=lowrow TO highrow
    FOR COL=lowcol TO highcol
      s+=USING$("(c=#_,r=#) &",COL,ROW,sArray(COL,ROW))+$CR
    NEXT
    s+=$CR
  NEXT
  ? s,,"Loop through all the elements"
'-------------------------------------------------------
  ? JOIN$(sArray(),$CR),,"or Join statement"
'-------------------------------------------------------
  s = ""
  FOR COL = lowcol TO highcol
    s+= sArray(COL,0) + $CR
  NEXT
  ? s,,"Column names by looping"
'-------------------------------------------------------
  s = ""
  FOR COL = lowcol TO highcol
    s+= USING$("& (column #)",sArray(COL,0),COL) + $CR
    FOR ROW = 1 TO highrow
      s+=sArray(COL,ROW) + $CR
    NEXT
    s+=$CR
  NEXT
  ? s,,"Display any column in recordset
END FUNCTION