SQLitening Support Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the SQLitening support forums!

Author Topic: Introduction  (Read 1427 times)

dbinev

  • Newbie
  • *
  • Posts: 1
    • View Profile
Introduction
« on: August 12, 2016, 08:48:52 AM »

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...
Logged

cj

  • Master Geek
  • ****
  • Posts: 700
    • View Profile
Re: Introduction
« Reply #1 on: August 12, 2016, 06:08:06 PM »

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
Logged

cj

  • Master Geek
  • ****
  • Posts: 700
    • View Profile
Re: Introduction
« Reply #2 on: August 13, 2016, 04:45:49 AM »

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
Logged