FUNCTION slOpen ALIAS "slOpen ...
IF thDab THEN EXIT FUNCTION '<--- add line in SQLitening.Bas and compile
Rather than test every program ever written, make above 1-line change to SQLitening.Bas
This is not an error in SQLitening, but a programming error not checking if database was open.
Calling slOpen will now just return if database is open and not create new handle and leak previous handle.
#INCLUDE "sqlitening.inc" 'test new sqlitening.dll with 3 open methods
SUB Test(sdatabase AS STRING)
LOCAL h AS LONG
slOpen sdatabase
h = slgethandle
slOpen sdatabase
IF h <> slGetHandle THEN ? "Memory leak"
END SUB
FUNCTION PBMAIN () AS LONG
Test "temp.tmp" 'test database file
Test ":memory:" 'test in-memory database
Test "" 'test temp database
? "Done"
END FUNCTION
Quote from: undefinedslGetHandle ([rsModChars String, rlSetNumber Long]) Dword
Returns the requested handle. ModChars will determine which handle is returned. The database handle may be used to call SQLite directly or can be passed to a different thread to be used in slOpen. The set handle may only be used to call SQLite directly and then only if in local mode. A %SQLitening_InvalidStringOrRequest error will occur if you try to get a set handle in remote mode.
ModChars:
· D = Return the open database handle. This is the default.
· S = Return the open set handle for set number passed in SetNumber.
Returns zero if an error occurs and the global return errors flag is on.
GLOBAL gs AS STRING
#INCLUDE "sqlitening.inc"
FUNCTION PBMAIN () AS LONG
slSetProcessMods "E2"
LOCAL x AS LONG
Logit "Open database only if not open"
FOR x = 1 TO 5
IF ISFALSE(slIsOpen) THEN slopen "junk.tmp","C": Logit USING$("handle #",slGetHandle)
NEXT
slClose
KILL "junk.tmp"
Logit ERROR$(ERR) + " killing junk.tmp"
[b]'Now show how to incorrectly use slOpen[/b]
Logit ""
Logit "Open database without testing if already open"
FOR x = 1 TO 5
slopen "junk.tmp","C"
Logit USING$("handle #",slGetHandle)
NEXT
slClose
KILL "junk.tmp"
LOGIT ERROR$(ERR) + " killing junk.tmp"
? gs
END FUNCTION
SUB LogIt(s AS STRING)
gs = gs + s + $CR
END SUB
#DIM ALL
MACRO money(colname)= CHR$("ltrim(printf('%.2f',",colname,"*.01),'0')",colname)
#INCLUDE "sqlitening.inc"
FUNCTION PBMAIN () AS LONG
LOCAL sql,sColDel,sRowDel,rs() AS STRING
slopen "sample.db3"
sql = "select manuf,redref,"+ money("PRICE") + " from parts limit 20"
slselary sql,rs()
sColDel = " "
sRowDel = $CR
? JOIN2(rs(),sColDel,sRowDel),,USING$("Rows #_, Cols #",UBOUND(rs,2),UBOUND(rs))
END FUNCTION
FUNCTION JOIN2(rs() AS STRING,sColumnDelimiter AS STRING,sRowDelimiter AS STRING) AS STRING
LOCAL sb AS ISTRINGBUILDERA
sb = CLASS "STRINGBUILDERA"
'sb.capacity = 1024*1000 'does well without capacity
LOCAL c AS LONG
LOCAL LowCol AS LONG
LOCAL HighCol AS LONG
LOCAL HighCol_minus1 AS LONG
LOCAL r AS LONG
LOCAL LowRow AS LONG
LOCAL HighRow AS LONG
LowCol = LBOUND(rs,1)
HighCol= UBOUND(rs,1)
HighCol_minus1 = HighCol-1
LowRow = LBOUND(rs,2)
HighRow= UBOUND(rs,2)
FOR r = LowRow TO HighRow
FOR c= LowCol TO HighCol_minus1
sb.add rs(c,r)
sb.add sColumnDelimiter
NEXT c
sb.add rs(c,r)
sb.add sRowDelimiter
NEXT r
FUNCTION = sb.string
END FUNCTION
FUNKTION_GU:
'===========
'
GU_SELECT:
slOpen TRIM$(KOM.DATABAS)
SET_NUMMER = slGetUnusedSetNumber
SEL_STRANG = "SELECT * FROM ART WHERE ARTNR= " + $SQ + TRIM$(ART.ARTNR) + $SQ
SVAR = slSel(SEL_STRANG, SET_NUMMER) ' Ska ge noll
IF SVAR <> 0 THEN
KOM.FELTEXT = "SYSTEMFEL i ARTIO GU slSel=" + STR$(SVAR) <<============
GOTO SYSTEMFELHANTERING
EXIT SUB
END IF