SQLite3 BaseFunction-Include for Win + Lin + Unicode

Share your advanced PureBasic knowledge/code with the community.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

This looks great.

I had been wanting to use prototypes but needed blob ( ie prepare, step finalize) support for my applications.

Today's additions should fill the bill.

Many thanks for your contributions.

cheers
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 575
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Post by bembulak »

I'm sooo late.

This looks great - I think it's pretty cool that your sources are crossplattform!

Thanks!
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Small Bugfix in both versions, thx to kiffi for bugreport
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

I really apreciate all the effort that has gone into putting this together.

I do have a question regarding converting to use this.

I have a rather involved program using sqlite3 somewhat extensively, based on Kiffi's fine wrapper. In looking to convert it to this code, I find it to be a little more involved than just replacing the function names. Parameters have been switched in the procedures, callback's added, etc.). Net is it will involve some work, and based on my history, then some re-work :).

My question is, what are the benefits to the prototype approach over the previous approach. When I start looking at the database access itself, I don't really see any appreciable differences, but I may well be missing something.

In the opinion of the 'experts' are their benefits sufficient to make it worth my while converting, and if so, how might I understand what they are?

Sorry for the 'newbie'ish question, but I still have a lot to learn about both sqlite and PureBasic.

Thanks for your time.

cheers
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

This Version is a bit easier then PBOSL_SQLite3, i hope, only real usefull
functions implemented.
This Version have full Unicode-Support (UTF-8 in Ansi- or Unicode-Mode)
Full Support for Linux, MacOS and Windows.

Kiffi himself uses my version :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Thanks for your quick response. You must never sleep, or you're a 'team' of people :) - And I'm in no way attempting to criticise or belittle your fine work.

I have no reservations about using this code and will do so in future sqlite based projects. My qustion is really regarding any benefit to be achieved in converting an existing program which uses Kiffi's wrapper to utilize this instead. Would there be any 'benefits' I would see in that program, besides access to unicode and a few more functions? Is this code in any way more 'robust' than kiffi's. That is - is "If SQ3\exec" in some way 'better' than "hResult = CallCFunctionFast(sqlite3_exec, lDataBaseHandle, sSQLQuery, #Null, #Null, @ReturnValue)"? And if it is, could someone explain how?

Just wanting to understand if it's worth the effort of converting an existing large program, or if should just wait for the next project :)

cheers
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

rsts wrote:That is - is "If SQ3\exec" in some way 'better' than "hResult = CallCFunctionFast(sqlite3_exec, lDataBaseHandle, sSQLQuery, #Null, #Null, @ReturnValue)"? And if it is, could someone explain how?

Code: Select all

Procedure.l SQLiteExecute(hDB.l, Statement.s, callback.l = 0)
  If SQ3\exec ; check only if functionpointer
    If Not SQ3\exec(hDB, Statement, callback); give only on #SQLite_OK a #true, errormessage is stored in errmsg, is not required to check here
      ProcedureReturn #True
    EndIf
  EndIf
  ProcedureReturn #False
EndProcedure
see comments, and it's shorter than kiffis errorhandling

Code: Select all

CallCFunctionFast
You should ever use prototypes in PB4, is more sure :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Thanks again for your response.

Might there be any explanation of the return values of true or false for sqlitestep? In looking at the code I can't determine how it's determining an appropriate return. Is it checking for #SQLITE3_OK and returning true/false based on that? If so, how might I determine when either #SQLITE3_ROW or #SQLITE3_DONE are returned versus some other return code?

cheers
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

All results like PB, <> 0 is good!
If a value 0, so you have to check this with for example: SQLiteErrorMsg(hDB.l)

SQLiteErrorCode(hDB) give you the normal errorcode, in errorcode is 0 the best :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
michel
Enthusiast
Enthusiast
Posts: 142
Joined: Mon Feb 19, 2007 5:47 pm
Location: Luxemburg

Post by michel »

Hello,

I recently switched from the former PBOSL-libraries to yours but I have problems with the "german Umlauts". My dbase is encoded in UTF8 and without the compiler unicode switch set, I see no longer any "Umlaut". Can you give me a tip what I could do?

michel
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

Hello michel,
michel wrote:Can you give me a tip what I could do?
the latest Version is 'umlaut-fixed'. See the first posting. ;-)

Greetings ... Kiffi
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
michel
Enthusiast
Enthusiast
Posts: 142
Joined: Mon Feb 19, 2007 5:47 pm
Location: Luxemburg

Post by michel »

I just discovered that my db is encoded in codepage 1252 (Ansi latin I). How can I transform data to UTF-8?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Update, both Version!

SQLiteExecute(), added optional para for callback

SQLiteOpen(), added flag for ASCII(Ansi) Mode
This works only in ASCII-Mode and is only to convert your old db's
In Unicode-Mode this flag is ignored!

The ASCII-Flag have global affect, please use it only in this form:

Code: Select all

If SQLiteInit()
  hDB = SQLiteOpen("MyDB", #True)
  ; reading
  SQLiteClose(hDB.l)
  hDB = SQLiteOpen("MyDB", #False)
  ;writing
  SQLiteClose(hDB.l)

EndIf
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

More examples

Post by Fangbeast »

Thomas, I can't see how to use blobs in a complex table from the example, feeling pretty dumb at the moment.

Could you combine your example that stores 5 records with your example that stores blobs so there are blobs in every record and show how to select a specific record including the blob for that record?

Sorry to bother you.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply