• Welcome, Guest. Please login.
 
August 07, 2020, 01:18:05 pm

News:

Welcome to the SQLitening support forums!


Recent posts

Pages 1 ... 4 5 6 7 8 ... 10
51
You've got Questions? We've got Answers! / Re: Would This Work?
Last post by Fredrick Ughimi - November 25, 2019, 08:26:38 am
Hello CJ,

Thanks. This is quite useful

I would try it out in a couple of days time.
52
You've got Questions? We've got Answers! / Re: Would This Work?
Last post by cj - November 24, 2019, 07:40:45 pm
SQLiteningServer.Cfg:
Port=51234
Hosts=192.168.0.2

Logins using slConnect:
The local computers connect to the local IP address or machine name and port of the server.
The remote computers connect to the remote IP address and port of the server.

Router:
The router needs to forward the local IP address and port to the server machine.
The IP address at command prompt of server: Type IPCONFIG  it is the IPV4 address.
I would use the address reservation page of the router to lock in the IP address of the server
so it never changes if the network is rebooted.

Windows Firewall:

SQLiteningServer.exe needs to be added to "Allow an app through the firewall."

Shortcuts:
Mark "Run as Administrator" to SqliteningServer.exe and SqliteningServerAdmin.exe

SQLitening is not secure over the internet.  Connections are not encrypted or authenticated.

CubeSQL seems to be a lot like SQLitening and uses JSON.  It might be an option.
https://sqlabs.com/cubesql

SQLTools might also be an option to consider and use another SQL.



Test server with 12 connections by using threads

#INCLUDE "win32api.inc"
#INCLUDE "sqlitening.inc"
GLOBAL gs() AS STRING
FUNCTION PBMAIN () AS LONG
 LOCAL x,hThread AS LONG
 DIM gs(12) 'each user puts recordset into an element
 FOR x = 1 TO UBOUND(gs)
  THREAD CREATE MyThread(x) TO hthread
  THREAD CLOSE hThread TO hThread
 NEXT
 DO:SLEEP 50:LOOP UNTIL THREADCOUNT=1
 ? JOIN$(gs(),$CR)
END FUNCTION

THREAD FUNCTION MyThread(BYVAL Num AS LONG) AS LONG
 DIM s() AS STRING
 slConnect "192.168.0.2",51234
 slOpen "sample.db3"
 slselary "select rowid,redref from parts where rowid=" + STR$(Num),s(),"Q9c"
 gs(Num) = JOIN$(s(),$CR)  'put into array
 slDisconnect
END FUNCTION
53
You've got Questions? We've got Answers! / Re: Would This Work?
Last post by Fredrick Ughimi - November 24, 2019, 12:21:59 pm
Hello CJ,

Thank you for your response.

>>If using the server everyone can share the server without a problem.

Yes I intend to use the server.

The question is how to physically connect the server computer to the client computers. We have 11 remote locations that would want to connect to the server over the internet and 8 client computers that would be connected to server on a LAN since they are in the same building with the server computer.

Best regards.
54
You've got Questions? We've got Answers! / Re: Would This Work?
Last post by cj - November 24, 2019, 09:57:48 am
If using the server everyone can share the server without a problem.
I've read many reasons on the SQLite site why not to use SQLite peer to peer.

I am sure TLS with SocketTools would work by modifying the client and server code, but
the server would require a certificate.  I noticed SocketTools added some encryption
code, but that isn't unique to SocketTools. If you create your own certificates is
not suggested, but talking to SocketTools they might be interested.
It would be easy for them.



55
You've got Questions? We've got Answers! / Re: Would This Work?
Last post by Fredrick Ughimi - November 23, 2019, 10:37:34 am
I know there are security concerns using SQLitening over the Internet. Would using SocketTools with SQLitening solve the security issues?
56
You've got Questions? We've got Answers! / Would This Work?
Last post by Fredrick Ughimi - November 21, 2019, 06:35:12 am
Hello,

Just wondering if SQLitening can be used on a LAN and at the same time over the Internet. I imagine a scenario where users (staff) use the SQLitening Application on a LAN while the Boss accesses or uses the application over the Internet from a remote location.

Any ideas? Thanks.
57
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Fredrick Ughimi - November 17, 2019, 02:36:15 pm
Hello CJ & Bern,

Thank you for helping out to find a solution to this.

I think I would along with Bern's version as I have been able to add more fields to it and implement it.

I haven't been able to make CJ's version work for me. I still intend to take another look at it later on.

Thank you guys, I appreciate your efforts and I have learnt a lot from this.

Best regards.
58
You've got Questions? We've got Answers! / Balance Reports Compared
Last post by cj - November 15, 2019, 11:54:33 am
Both routines are compared in this posting.

Bern,
Nice, learned a lot!!

Bern routine results:
1 payment record must exist to return results for a client
2 credit balances do not display (they weren't asked for)
3 optional, modified to add payments (passed as negative amounts)

The CJ routine could eliminate the creating temp table by reading
through the recordset and handling the debit/credit as they occur.
Made it easier by just creating a temp file with the balances.

Also, for some reason when I dropped the what I thought was unneeded third column in the
union statement t1,t2,t3 the union was not always correct.  Need to look into that.
Leaving "as is" is suggested.

In this example CJ will return 4-records and Bern will return 2-records.
Fredrick, these differences should be considered.

#INCLUDE "sqlitening.inc"

FUNCTION showit(sql AS STRING) AS STRING
 LOCAL sArray() AS STRING
 slselary sql,sArray(),"Q9"
 FUNCTION = JOIN$(sArray(),$CR) + $CR
END FUNCTION

FUNCTION PBMAIN AS LONG
 bern
 cj
END FUNCTION

SUB InsertData
 slexe  "insert into T1 values(1,10),(1,20),(2,10),(4,100)"
 slexe  "insert into T2 values(1,30),(1,40),(2,10)"
 slexe  "insert into T3 values(1,-200),(2,0),(3,-1)"
END SUB

FUNCTION Bern AS LONG

 LOCAL s AS STRING
 KILL   "temp.db3":IF ERR THEN ? STR$(ERRCLEAR)
 slopen "temp.db3","C"

 slexe  "create table if not exists T1 (surname1 int,Amount1 int)"
 slexe  "create table if not exists T2 (surname2 int,Amount2 int)"
 slexe  "create table if not exists T3 (surname3 int,Amount3 int)"
 InsertData

 '? ShowIt("select * from t1") + $CR + ShowIt("select * from t2") + $CR + ShowIt("select * from t3")

 s=  "WITH"
 s+="   TempT1(TT1Surname,TT1Total) AS (SELECT Surname1, Amount1"
 s+="     FROM T1),"
 s+="   TempT2(TT2Surname,TT2Total) AS (SELECT Surname2, Amount2"
 s+="     FROM T2),"
 s+="   SumT1( ST1Surname, ST1Total) AS (SELECT TT1Surname, TOTAL( TT1Total)"
 s+="     FROM TempT1 GROUP BY TT1Surname),"
 s+="   SumT2( ST2Surname, ST2Total) AS (SELECT TT2Surname, TOTAL( TT2Total)"
 s+="     FROM TempT2 GROUP BY TT2Surname),"
 s+="   SumT3( ST3Surname, ST3Total) AS (SELECT Surname3, TOTAL( Amount3)"
 s+="     FROM T3 GROUP BY Surname3)"
 s+=" SELECT ST3Surname as acct, ST1Total + ST2Total + ST3Total as amt"
 s+="   FROM SumT3"
 s+="   INNER JOIN SumT1 ON ST3Surname = ST1Surname"
 s+="   INNER JOIN SumT2 ON ST3Surname = ST2Surname"
 s+="   WHERE ST1Total + ST2Total <> ST3Total" 'made <> instead of subtract

 '? s,,"Sql"
 ?  ShowIt(s)
 'DIM sArray() AS STRING
 'slselAry s,sArray(),"Q9"
 '? JOIN$(sArray(),$CR),,FUNCNAME$
 slClose

END FUNCTION

FUNCTION CJ () AS LONG

 LOCAL sData(),sBind AS STRING, x AS LONG
 KILL   "temp.db3"
 slopen "temp.db3","C"

 slexe  "create table if not exists t1 (surname1 int,amt int)"     'charges table1
 slexe  "create table if not exists t2 (surname2 int,amt int)"     'charges table2
 slexe  "create table if not exists t3 (surname3 int,amt int)"     'payments
 slexe  "drop table if exists TempBalances
 slexe  "create table TempBalances(acct unique,amt)"
 InsertData

 'combine tables and payments
 slselary " select surname1,sum(amt),'t1' from t1 group by surname1"  +_     'charges table1
          " union "                                      +_
          " select surname2,sum(amt),'t2' from t2 group by surname2"  +_     'charges table2
          " union "                                      +_
          " select surname3,sum(amt),'t3' from t3 group by surname3",sData() 'payments table3

 'update TempBalances() from above sData()
 FOR x = 1 TO UBOUND(sdata,2)
  sBind = slBuildBindDat(sdata(1,x),"T") + slBuildBindDat(sData(2,x),"T")
  slexebind "Insert into TempBalances values(?,?) ON conflict(acct) DO update SET amt=amt+" + sData(2,x),sBind
 NEXT
 ? showit("select * from TempBalances"),,FUNCNAME$
 slclose
END FUNCTION
59
You've got Questions? We've got Answers! / Re: Debtors List
Last post by cj - November 15, 2019, 02:04:58 am
balances.png

#INCLUDE "sqlitening.inc"

FUNCTION PBMAIN () AS LONG
 LOCAL sData(),sBind AS STRING, x AS LONG

 KILL   "temp.db3"
 slopen "temp.db3","C"

 slexe  "create table if not exists t1 (acct,amt)"     'charges table1
 slexe  "create table if not exists t2 (acct,amt)"     'charges table2
 slexe  "create table if not exists t3 (acct,amt)"     'payments
 slexe  "drop table if exists TempBalances;create table TempBalances(acct unique,amt)"

 slexe  "insert into t1 values(1,1000),(2,2000),(3,3000)"             'charges t1
 slexe  "insert into t2 values(4,4000)"                               'charges t2
 slexe  "insert into t3 values(4,-2000),(1,-500),(2,-1000),(3,-1500)" 'apply payments

 'combine tables and payments
 slselary " select acct,sum(amt),'t1' from t1 group by acct"  +_     'charges table1
          " union "                                      +_
          " select acct,sum(amt),'t2' from t2 group by acct"  +_     'charges table2
          " union "                                      +_
          " select acct,sum(amt),'t3' from t3 group by acct",sData() 'payments table3

 'update TempBalances() from above sData()
 FOR x = 1 TO UBOUND(sdata,2)
  sBind = slBuildBindDat(sdata(1,x),"T") + slBuildBindDat(sData(2,x),"T")
  slexebind "Insert into TempBalances values(?,?) ON conflict(acct) DO update SET amt=amt+" + sData(2,x),sBind
 NEXT
 ? showit("select * from TempBalances"),,"Balances"
END FUNCTION

FUNCTION showit(sql AS STRING) AS STRING
 LOCAL sArray() AS STRING
 slselary sql,sArray(),"Q9"
 FUNCTION = JOIN$(sArray(),$CR) + $CR
END FUNCTION
60
You've got Questions? We've got Answers! / Re: Debtors List
Last post by Bern Ertl - November 14, 2019, 12:56:02 pm
OK.  I played with cj's code and found the problem.  You cannot use Total() in a WHERE clause.  I reworked the statement and it compiles/works now.

#INCLUDE "sqlitening.inc"
GLOBAL gs AS STRING

FUNCTION PBMAIN () AS LONG
 KILL   "test.db3"
 slOpen ("test.db3", "C")
 'ServicesBill  changed to t1
 slExe "Create Table t1(Date TEXT, BillNo TEXT, HospitalNo TEXT COLLATE NOCASE, Surname1 TEXT, Othernames TEXT, Category TEXT," & _
 "Department TEXT, CodeNo TEXT COLLATE NOCASE, Service TEXT, amount1 REAL, Discount REAL, Status TEXT)"

 'Pharmacy Bill changed to t2
 slExe BUILD$("Create Table t2(RecNo TEXT, SNo TEXT, Date TEXT, InvoiceNo TEXT, HospitalNo TEXT, Surname2 TEXT,", _
 "ProductNo TEXT COLLATE NOCASE, Description TEXT, PatientCategory TEXT, Department TEXT, Quantity REAL, SellingPrice REAL, Discount REAL, Username TEXT)")

 'Payment       changed to t3
 slExe BUILD$("Create Table t3(ReceiptNo INTEGER, BillNo INTEGER, Date TEXT, HospitalNo TEXT, Surname3 TEXT, Othernames TEXT,", _
 "Category TEXT, Stage TEXT, PaymentMode TEXT, CheckNo TEXT, Amount3 REAL, Purpose TEXT, Department TEXT, Cashier TEXT)")

 LOCAL x AS LONG
 FOR x = 1 TO 1
  slexebind "insert into t1 values (?,?,?,?,?,?,?,?,?,?,?,?)",     REPEAT$(12,slbuildbindDat("1","T")) '12
  slexebind "insert into t2 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", REPEAT$(14,slbuildbindDat("1","T")) '14
  slexebind "insert into t3 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", REPEAT$(14,slbuildbindDat("1","T")) '14
 NEXT
 gs = CHR$( GetRs("select * from t1"),$CR,$CR,GetRs("select * from t2"),$CR,$CR,GetRs("select * from t3")) + $CR
 Bern
END FUNCTION

FUNCTION Getrs(sql AS STRING) AS STRING
 DIM s() AS STRING
 slSelAry sql,s(),"Q9c"
 FUNCTION = JOIN$(s(),$CR)
END FUNCTION

SUB Bern
LOCAL s AS STRING

s=  "WITH"
s+="   TempT1(TT1Surname,TT1Total) AS (SELECT Surname1, Amount1 - Discount"
s+="     FROM T1),"
s+="   TempT2(TT2Surname,TT2Total) AS (SELECT Surname2, Quantity * SellingPrice - Discount"
s+="     FROM T2),"
s+="   SumT1( ST1Surname, ST1Total) AS (SELECT TT1Surname, TOTAL( TT1Total)"
s+="     FROM TempT1 GROUP BY TT1Surname),"
s+="   SumT2( ST2Surname, ST2Total) AS (SELECT TT2Surname, TOTAL( TT2Total)"
s+="     FROM TempT2 GROUP BY TT2Surname),"
s+="   SumT3( ST3Surname, ST3Total) AS (SELECT Surname3, TOTAL( Amount3)"
s+="     FROM T3 GROUP BY Surname3)"
s+=" SELECT ST3Surname, ST1Total + ST2Total - ST3Total"
s+="   FROM SumT3"
s+="   INNER JOIN SumT1 ON ST3Surname = ST1Surname"
s+="   INNER JOIN SumT2 ON ST3Surname = ST2Surname"
s+="   WHERE ST1Total + ST2Total > ST3Total"

 DIM sArray() AS STRING
 slselAry s,sArray(),"Q9"
 'slSel s,0,"D"
 ? "Incorrectly attempt Bern statement" + $CR + JOIN$(sArray(),$CR) + STRING$(5,$CR) + "Tables contained:" + $CR + gs
END SUB

The output doesn't show anything because it's computing zero for TT1Total and TT2Total with the dummy data in this code.  You can remove the WHERE clause from the statement to see it's computing -1 for ST1Total + ST2Total - ST3Total. 

This statement flattens all three tables into a single record per Surname/HospitalNo.  The final SELECT is using T3 as the leftmost FROM table, so the output will only list Surname/HospitalNo records if a record exists in (Sum)T3.  If you want results where no record (for Surname/HospitalNo) exists in T3, you would need to adjust the statement to base the results on either SumT1 or SumT2.

I'm not sure how to combine the output to list every Surname/HospitalNo record that exists across all three tables with the db schema as listed.  If you have another table with a master list of Surname/HospitalNo records, you could use that as the base and use LEFT OUTER JOINS on SumT1, SumT2 and SumT3.
Pages 1 ... 4 5 6 7 8 ... 10