• Welcome, Guest. Please login.
 
August 22, 2019, 10:09:48 pm

News:

Welcome to the SQLitening support forums!


FreeBasic

Started by cj, November 01, 2016, 02:04:07 pm

Previous topic - Next topic

cj

November 01, 2016, 02:04:07 pm Last Edit: November 01, 2016, 02:12:16 pm by cj
Is FreeBasic code easy to convert from PowerBASIC?  http://www.freebasic.net
Anyone have an example like this in FreeBASIC

#INCLUDE "sqlitening.inc"
%DropTable = 0

FUNCTION PBMAIN () AS LONG  'GetHighest.bas

  LOCAL sResult,sql AS STRING,recnum AS LONG

  'open database
  IF slopen ("test.db3","C") THEN ? slGetError: EXIT FUNCTION

  'drop table
  IF %DropTable THEN slexe "drop table if exists T1"

  'create table
  slexe "create table if not exists T1(recnum integer primary key,Column2)"

  'get highest record and add 1
  sql = "select max(recnum) from T1"
  RecNum = VAL(GetData(sql)) + 1

  'insert record new highest record
  slexe "insert into T1 values(null,'I am record" + STR$(RecNum) + "')"

  'get lowest record
  sql = "select * from t1 order by recnum limit 1"
  sResult = GetData(sql)

  'get highest record
  sql = "select * from T1 where recnum = (select Max(recnum) from T1)"
  sResult+= GetData(sql)
  ? sResult,,"Lowest/Highest"
 
END FUNCTION

FUNCTION Getdata(sql AS STRING) AS STRING
  LOCAL sArray() AS STRING
  slSelAry sql,sArray(),"Q9c"
  FUNCTION = JOIN$(sArray(),$CR) + $CR
END FUNCTION

Bern Ertl

I have never used Freebasic.  Does it have a facility for using DLLs?  You might need to do some conversion of the .inc file if it handles binding (ie. uses a different syntax/schema) to DLLs differently from PowerBASIC.

cj

November 02, 2016, 12:42:16 pm #2 Last Edit: November 02, 2016, 12:44:03 pm by cj
I was hoping Mr Squires might have a demo since he has Firefly for FreeBasic.
I saw Vivian's Zales post on PowerBASIC that they won't be releasing new products.
https://forum.powerbasic.com/forum/announcements-articles-and-support-faqs/product-announcements/754174-status-of-powerbasic-inc

Paul Squires

I haven't used SQLitening with FreeBasic. It would be nice to have an interface to FreeBasic, I just haven't had an overriding need to work on such a beast. :)

Paul Squires

I am working on a FreeBasic version now. Just need to modify the include file and get it to work with the universal version of sqlitening. Also need to create the .a linking file. I will report back once I get this all working.

cj


Paul Squires

Firstly, I am going to try to get it working just using a standard console window. From there it is trivial to put it into FireFly.

Paul Squires

January 10, 2017, 09:55:38 pm #7 Last Edit: January 11, 2017, 11:39:11 pm by Paul Squires
Conversion to FreeBasic done (well, about 99% done). I have not converted the slRunProc function yet because, quite frankly, I don't yet totally understand the calling parameters.

The attached package contains the FreeBasic Include file, called "SQLiteningFB.bi"

You will need to ship the universal dll with your applications SQliteningU.dll, in addition to SQLitening.dll and SQLite.dll

Also in the package are two library import files libSQLitening.dll.a and libSQLiteningU.dll.a. You need to copy those to the \lib\win32 folder of your FB installation or you won't be able to compile without errors. You do not ship those files with your application. They are only needed for compiling.

I have included an FB version of the ExampleA.bas test code so you can see that everything works in local and remote modes.

Please let me know if you come across anything that doesn't work correctly.

EDIT: Jan 11, 2017:  Corrected libSQLitening.dll.a import file. Recompiled all DLL's and EXE's. Downloaded latest sqlite DLL. Created a FB port of ExampleB.bas example file.


cj

January 11, 2017, 09:12:25 am #8 Last Edit: January 11, 2017, 07:00:05 pm by cj
Download and install FreeBasic
http://freebasic.net/

Download Mr. Squires FreeBasic.rar:
http://sqlitening.com/support/index.php?action=dlattach;topic=9635.0;attach=686

Create a test folder and install SQLitening routines:
Create a folder like \FB
UNZIP FreeBASIC.rar  into \FB
Copy "libSQLiteningU.dll.a" and "libSQLitening.dll.a"   shortcut copy c:\fb\*.a  "\program files\freebasic\lib\win32

Create a program:
rem easy.bas
#INCLUDE ONCE "sqliteningFB.bi"
#INCLUDE ONCE "string.bi"
DIM AS LONG NumRecs
slOpen( "sample.db3" )
slSel "SELECT * FROM PARTS"
DO WHILE slGetRow
NumRecs += 1
LOOP
? NumRecs

Compile program and run:
"\program files\freebasic\fbc.exe" easy.bas -s gui
easy

Create batch file c.bat to compile and test:
erase %1.exe
"\program files\freebasic\fbc.exe" %1.bas -s gui
%1
rem syntax: c ExampleA
rem syntax: c  easy

Notes:
slSelAry is not supported.
FreeBASIC creates 32-bit executables.
The sqlite3.dll in freebasic.rar is version 3.7.13
Current version as of 1/11/17 is version 3.16.2
Download at http://sqlite.org/download.html  (Precompiled Binaries for Windows 32-bit DLL (x86)


Thank you, Paul Squires!!

As Paul said in post #7, please post anything you find.




cj

January 11, 2017, 11:14:17 am #9 Last Edit: January 11, 2017, 11:20:29 am by cj
1. Getting 23 -version conflict
Replaced SqliteningClient.dll with the more current one.
The one in the FreeBasic.rar is also 54,784 bytes, but ran FC and it is much different.
After replacing it, programs are running fine on my local server and remote server.

2. slDisconnect undefined reference to slDisconnect@0



#INCLUDE ONCE "sqliteningFB.bi"
#INCLUDE ONCE "string.bi"

function MainOrSomething() AS integer

dim AS long NumRecs
dim AS long col, columns
dim AS string crlf = CHR(13,10)
dim s AS STRING
cls
slconnect "45.40.133.16",51234
slopen "sample.db3","C"
slSel "SELECT rowid, manuf,product,price from parts limit 3"
columns = slGetColumnCount
if columns then
   do while slGetRow
    for col = 1 To columns
      s += slf(col) + CHR$(9)
    next
    mid$(s,len(s)-1) = crlf 'end line with CR
    NumRecs += 1
   LOOP
   ? s
   ? "NumRecs";Numrecs
  else
   ? "No recordset returned"
  end if
  'sldisconnect 'function result was not explicitly set undefined reference to 'slDisconnect@0'
end function

MainOrSomething


Bern Ertl

Quote from: Paul Squires on January 10, 2017, 09:55:38 pm...  I have not converted the slRunProc function yet because, quite frankly, I don't yet totally understand the calling parameters.
...


I use slRunProc quite extensively.  Maybe I can clarify?

rsProcName (String) - a coded string value that contains a single letter designating which DLL to load and which function within that DLL to call.  Example usage:  "TGetServerDateTime" means to call the DLL named SQLiteningProcsT.DLL and to call the function named GetServerDateTime within that DLL.

blParm1 (Long), blParm2 (Long), bsParm3 (String), bsParm4 (String) - 4 variables passed by reference (to the target function within the target DLL) so that the function called can send and/or receive data.  You define the meaning of these parameters when you create the target function in the DLL.  The parameter structure here is fixed, much like the parameters for a callback function in windows.

slRunProc allows you to add server side processing to an SQLitening app that runs remotely.

cj

January 11, 2017, 01:09:46 pm #11 Last Edit: January 11, 2017, 07:04:12 pm by cj
I've only been using FreeBASIC for hours so please be gentle.
Don't like having to use the console for viewing the output so added a shellexecute to a text file.
Took me longer to figure out include files than everything else combined.

Not sure how to get rid of the console flashing for a second.
Not sure, yet if there is a FREEFILE function.

From above post

1. Getting 23 -version conflict
Replaced SqliteningClient.dll with the more current one.
The one in the FreeBasic.rar is also 54,784 bytes, but ran FC and it is much different.
After replacing it, programs are running fine on my local server and remote server.

2. slDisconnect undefined reference to slDisconnect@0

I don't think slSelAry function is possible with this interface, but might make an interesting project.

Have not yet tested other functions.


Hope this helps others get started.


#INCLUDE ONCE "sqliteningFB.bi"
#INCLUDE ONCE "windows.bi"
#INCLUDE ONCE "win\shellapi.bi"   

declare sub showit(s as string)
declare function MainOrsomething as integer

function MainOrSomething() AS integer

dim NumRecs as long
dim AS long col, columns
dim AS string crlf = CHR(13,10)
dim AS string s
dim result AS LONG

slconnect "45.40.133.16",51234
slopen "sample.db3","C"
slSel "SELECT rowid, manuf,product,price from parts limit 20"

columns = slGetColumnCount
if columns then
   do while slGetRow
    for col = 1 To columns
      s += slf(col) + CHR$(9)
    next
    mid$(s,len(s)-1) = crlf 'end line with CR
    NumRecs += 1
   LOOP
   showit(s)
   
  else
   ? "No recordset returned"
   sleep
  end if

  REM sldisconnect 'function result was not explicitly set undefined reference to 'slDisconnect@0'
  function = 0
end function

sub showit(s as string)
dim hfile as long
dim sFile  as string
sFile = "test.txt"
hFile = FREEFILE
open sFile for output as #hfile
print #hFile, s
close #hFile
hFile = ShellExecute(null, "open", sfile, null,null,sw_normal)  'implicit conversion
end sub

MainOrSomething


Paul Squires

Hi guys, thanks for the posts and followup information. Appreciate it. I will get slRunProc implemented.

i also noticed that linking failed when slClose is used in my code. This might be similar to the slDisconnect issue. Maybe I need to regenerate the libsqlitening.dll.a linking file. I will look at that.

An easy way to work with FreeBasic is to use my WinFBE editor. That's what I am using for all my FB projects now.
https://github.com/PaulSquires/WinFBE/releases

I am trying to create enough test code that all of the sqlitening functions are covered and working correctly. Also, if you need code that emulates all of PowerBasic's awesome string handling then take a look at my ANSI versions (search my forum for FF_JOIN for example), or use the unicode enabled versions that are packaged with Jose Roca's CWindow package (also found in my forums). http://www.planetsquires.com/protect/forum/index.php?board=39.0

Paul Squires

Quote from: cj on January 11, 2017, 01:09:46 pm
Not sure how to get rid of the console flashing for a second.

Use the compiler switch "-s gui" (without the quotes of course). This sets the application to use gui rather than console.

QuoteNot sure, yet if there is a FREEFILE function.

There sure is. Works the same as PowerBasic.


cj

Thanks, Paul.
Made changes to above source.

I'm trying to get rid of the warning implicit conversion

SUB showit(s AS STRING)
DIM hFile  AS LONG
DIM sFile  AS STRING *32
sFile = "test.txt"
hFile = FREEFILE
OPEN sFile FOR OUTPUT AS #hFile
PRINT #hFile, s
CLOSE #hFile
hFile = ShellExecuteA(BYVAL 0, "open", BYVAL sfile, BYVAL 0,BYVAL 0,sw_normal)  'implicit conversion
END SUB

rem FUNCTION ShellExecuteA(BYVAL hwnd AS HWND, BYVAL lpOperation AS LPCSTR, BYVAL lpFile AS LPCSTR, BYVAL lpParameters AS LPCSTR, BYVAL lpDirectory AS LPCSTR, BYVAL nShowCmd AS INT_) AS HINSTANCE