• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

Recent posts

#2
You've got Questions? We've got Answers! / Re: How to be able to see if a...
Last post by cj - January 01, 2024, 03:33:43 PM
Here is a fix for slSetRelNameLocks  (requires using server)
https://sqlitening.planetsquires.com/index.php?topic=9440.msg25473
#3
You've got Questions? We've got Answers! / Re: How to be able to see if a...
Last post by cj - January 01, 2024, 03:19:38 PM
slSetRelNamedLocks  does not work without SQLitening server and has some problems.
These functions fix that problem and are easy to use.

#INCLUDE ONCE "sqlitening.inc"

FUNCTION PBMAIN AS LONG

slconnect "192.168.0.2"
slOpen    ":memory:"
slexe    "create table t1(c1)"

IF slLock  ("A") THEN IF sllock  ("Z") THEN ? "Locked A,Z"
? slGetLockNames
IF slUnlock("A") THEN IF slUnlock("Z") THEN ? "Unlock A,Z"

END FUNCTION
'=========================================================
FUNCTION slGetLockNames AS STRING
'connect and open database before call
LOCAL s1,s2 AS STRING, x AS LONG
s1 = slGetStatus(1)
IF LEN(s1) = 0 THEN EXIT FUNCTION
REPLACE $VT WITH "," IN s1
REPLACE $BS WITH "," IN s1
FOR x = 2 TO PARSECOUNT(s1) STEP 8
  s2 = s2 + PARSE$(s1,x) + ","
NEXT
FUNCTION = s2
END FUNCTION
'=========================================================
FUNCTION slIsLock(sId AS STRING) AS LONG
LOCAL Found  AS LONG 'Return 1 on success
LOCAL s      AS STRING
s = slGetLockNames
IF INSTR(s,sID + ",") THEN
  FUNCTION = 1
END IF
END FUNCTION
'=========================================================
FUNCTION slLock(sId AS STRING) AS LONG
LOCAL Found  AS LONG 'Return 1 on success
LOCAL s      AS STRING
s = slGetLockNames
IF INSTR(s,sID + ",") THEN Found = 1
IF Found = 0 THEN    'not found
  slSetRelNamedLocks "+" + sID,"T10000 E0"
  IF slGetErrorNumber = 0 THEN FUNCTION = 1
END IF
END FUNCTION
'=========================================================
FUNCTION slUnlock(sId AS STRING) AS LONG
LOCAL Found  AS LONG  'Return 1 on success
LOCAL s      AS STRING
s = slGetLockNames
IF INSTR(s,sID + ",") THEN Found = 1
IF Found = 1 THEN    'must be found
  slSetRelNamedLocks "-" + sID,"T10000 E0"
  IF slGetErrorNumber = 0 THEN FUNCTION = 1
END IF
END FUNCTION'

#4
You've got Questions? We've got Answers! / Re: How to be able to see if a...
Last post by Fim - January 01, 2024, 12:38:47 PM
"IF slLock("fim") THEN
ELSE
slUnlock("fim")
END IF"

No,I am using OPEN LOCK_FIL_NAMN FOR OUTPUT AS #TEST_LOCK_FIL
#5
You've got Questions? We've got Answers! / Re: How to be able to see if a...
Last post by cj - January 01, 2024, 12:24:47 PM
Are you using slConnect (which is required?)

IF slUnLock("fim") THEN
   sllock("fim")
END IF






#6
You've got Questions? We've got Answers! / Re: How to be able to see if a...
Last post by Fim - December 27, 2023, 02:57:00 PM
Nothing is going well for me.
I've tried all sorts of solutions, but it's always something small that fails.
So I have decided to use file system and lock a file by doing "open output" in my main program.
Then when I start a new instance of the main program, I count the number of locked files by trying to do "open output".
In this way, for each new instance of my main program, I can report how many users are running.
I appreciate your commitment to finding a solution, Thank you.
This is what my program looks like now:

RAKNING_ANTAL_ANVANDARE:
'=======================
'
' I tråden BAKGRUND som finns med i alla kommadoprogram + WINOVA
' så sker en låsning i form av OPEN OUTPUT av en fil
' vars namn är IP-adressen. Det finns mer utförlig beskrivning där.

' Nu är det rätt enkel, vi går igenom alla registrerade IP-adresser i tabellen INL.
' För varje IP-adress undersöker vi om det finns en låst fil namnet IP-adress.
' Görs med försök av en OPEN OUTPUT.
' Lyckas vi med filöppningen, måste vi omgående släppa låsning med CLOSE och
' sedan gå  vidare till nästa IP-adress.
' Är filen låst, räknar vi upp antalet användare och går vidare till nästa IP-adress.
' Denna metod verkar vara helt vattentät, har testkört med över 100 instanser ocg 5 olika IP-adresser.

RAA_START:
    ANTAL_ANVANDARE = 0
    KOM.SQL_SATS = "SELECT * FROM INL"
    CALL INLIO(KOM, INL, "SQLS")
    TEST_LOCK_FIL = FREEFILE

RAA_NASTA:
    CALL INLIO(KOM, INL, "GN")
    IF LANGD(KOM.SVAR) > 0 THEN GOTO RAA_EXIT

RAA_LOCK_FORSOK:
    ON ERROR GOTO 0
    ERR = 0
    LOCK_FIL_NAMN =  TRIM$(INL.IP_ADRESS) + ".INLOGGAD"
    ERR = 0
    OPEN LOCK_FIL_NAMN FOR OUTPUT AS #TEST_LOCK_FIL
    SVAR = ERRCLEAR
    IF SVAR <> 0 THEN
        INCR ANTAL_ANVANDARE
        GOTO RAA_NASTA
    END IF
    CLOSE #TEST_LOCK_FIL
    GOTO RAA_NASTA
RAA_EXIT:

ANTAL_ANVANDARE are NUMBER_OF_USERS
#7
You've got Questions? We've got Answers! / Re: How to be able to see if a...
Last post by cj - December 26, 2023, 04:50:31 PM
It might be easier except I can't get any return code other than 0
If I call with "+a" multiple times no error.  If I call with "-a" multiple times no error.
Needs "+" or "-" to avoid error 19

At least this works:
If slLock("something") THEN ? "Locked":slUnlock("something")

What am I doing wrong?

Note:  Made these modifications to helper functions:
Added "E0"
If slGetErrorNumber = 0 THEN FUNCTION = 1

I don't really need these functions because when in a record I redisplay the screen every 5-seconds
if anyone changed the current data.  I do this by keeping current buffer in a string and compare
to the new buffer every 5-seconds.  If they don't match, I display new data and display a message.

#INCLUDE ONCE "sqlitening.inc" 'slLock.bas

FUNCTION PBMAIN AS LONG

 LOCAL x,ecode AS LONG
 slconnect "192.168.0.2",5802 '<--- requires sqlitening server
 slOpen    "Junk.db3","C"
 slexe    "drop table if exists t1"
 slexe    "create table if not exists t1(c1 text)
 slexe    "insert into t1 values('apples'),('peaches'),('pumpkin pie')"
 FOR x = 1 TO 2
  ecode = slSetRelNamedLocks("+a", "T0", "", 0, "E2")
  IF slGetErrorNumber THEN ? slGetError,,"sql error":EXIT FUNCTION
  ? slGetLockNames,,"Ecode" + STR$(ecode)
 NEXT
END FUNCTION
'=========================================================
FUNCTION slGetLockNames AS STRING
 'connect and open database before call
 LOCAL s1,s2 AS STRING, x AS LONG
 s1 = slGetStatus(1)
 IF LEN(s1) = 0 THEN EXIT FUNCTION
 REPLACE $VT WITH "," IN s1
 REPLACE $BS WITH "," IN s1
 FOR x = 2 TO PARSECOUNT(s1) STEP 8
  s2 = s2 + PARSE$(s1,x) + ","
 NEXT
 FUNCTION = s2
END FUNCTION
'=========================================================
FUNCTION slIsLock(sId AS STRING) AS LONG
 LOCAL Found  AS LONG 'Return 1 on success
 LOCAL s      AS STRING
 s = slGetLockNames
 IF INSTR(s,sID + ",") THEN
  FUNCTION = 1
 END IF
END FUNCTION
'=========================================================
FUNCTION slLock(sId AS STRING) AS LONG
 LOCAL Found  AS LONG 'Return 1 on success
 LOCAL s      AS STRING
 s = slGetLockNames
 IF INSTR(s,sID + ",") THEN Found = 1
 IF Found = 0 THEN    'not found
  slSetRelNamedLocks "+" + sID,"T10000 E0"
  IF slGetErrorNumber = 0 THEN FUNCTION = 1
 END IF
END FUNCTION
'=========================================================
FUNCTION slUnLock(sId AS STRING) AS LONG
 LOCAL Found  AS LONG  'Return 1 on success
 LOCAL s      AS STRING
 s = slGetLockNames
 IF INSTR(s,sID + ",") THEN Found = 1
 IF Found = 1 THEN    'must be found
  slSetRelNamedLocks "-" + sID,"T10000 E0"
  IF slGetErrorNumber = 0 THEN FUNCTION = 1
 END IF
END FUNCTION'
#8
You've got Questions? We've got Answers! / Re: How to be able to see if a...
Last post by Fim - December 26, 2023, 02:29:11 PM
I think this is easier.
RETURNCODE = slSetRelNamedLocks(LOCK_NAME, "T0", "SELECT * FROM INL LIMIT 0", 0, "E0")

RETURNCODE = 0, unlocked
RETURNCODE = 11, locked
In neither case does an error code appear on the screen.
How about that?
#9
You've got Questions? We've got Answers! / Re: How to be able to see if a...
Last post by cj - December 25, 2023, 06:03:45 PM
Fim,
I had to search and found using "namedlock"
I added 4 functions.  slIsLock should do what you want..

https://sqlitening.planetsquires.com/index.php?topic=9803.msg26798;topicseen#msg26798

FUNCTION PBMAIN AS LONG
 slconnect "192.168.0.2",12345
 slOpen ":memory:"
 IF slIsLock("99") THEN ? "Already locked"  ELSE ? "Not locked"
 IF slLock  ("99") THEN ? "lock success"    ELSE ? "lock failed"
 IF slUnlock("99") THEN ? "unlock success"  ELSE ? "unlock failed"
END FUNCTION





#10
You've got Questions? We've got Answers! / Re: How to be able to see if a...
Last post by Fim - December 25, 2023, 12:52:02 PM
You have a better memory than I
I am 81 years.