• Welcome, Guest. Please login.
 
September 17, 2019, 09:54:51 am

News:

Welcome to the SQLitening support forums!


Newbie - Starting out with SQLite Client/Server

Started by Fredrick Ughimi, April 16, 2008, 06:34:42 am

Previous topic - Next topic

Fredrick Ughimi

Hello Paul,

>>You are only setting the database name variable when the database does not exist ot exist...

Oops! You are right. Should have done this (sDatabase = "EmlenPharmacyProDB.db3") before testing. The DB actually exist.

>>You should create your database using SQLite Expert and then use code like the following to alert the user in situations where the database does not exist or is not installed with your application.

That is what I did. I created my DB and table using SQLite Expert. Made the correcttion, but the error 1 is still there.

Best regards,


Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Paul Squires

In your sSQL statement you forgot to separate the "INSERT INTO" statement from the "COMMIT TRANSACTION" with a semi-colon ";".

:)

Fredrick Ughimi

Hello Paul,

You are right once again. Its now working. You have Eagle eyes.  ;)

Thank you so much.

Best regards,
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Jim Harre

I'm working on a simple "Today in History" app based on Patrick Kincaid's "Today" program from yesteryear. There's a ton of data. Using sample_create.bas as a starting point, I got it working building a table from the text data.

But when adding records, I get "Error: 1 during sql3_exec (Adding record)." It seems that single quotes in the text made it unhappy. So, I surrounded the text with double quotes and that worked OK for a few more lines. But it really gets confused when it sees text like this:
   first running of SF's famed "Bay to Breakers" race (7.63 miles)

Anyone have an idea how to prep the text to make it acceptable to SQLite?  ???

Paul Squires

Hi Jim,

First off, thanks a million for using the SQLite3 Client/Server code. I really appreciate it. The more people who use this the more incentive it gives me to continue work on it.

You have encountered a common problem with text strings and SQL. When you are trying to store a string with embedded single quotes in it (i.e. SF's) then you need to escape the quote with another quote. The library provides a built in function that does this for you. It is called sql3_fix. To be safe, you should probably wrap all of your text in this function.

For example:


   sString = "first running of SF's famed "Bay to Breakers" race (7.63 miles)"
   sSQL = "BEGIN IMMEDIATE TRANSACTION; " & _
          "INSERT INTO parts (manuf) VALUES ( '" & sql3_Fix( sString ) & "');" & _
          "COMMIT TRANSACTION;"
   errcode = sql3_exec( hSession, sSQL )


Jim Harre

Ahhh, thanks, Paul!

I knew I was missing something. (Well, that and an extra set of single quotes around the text that I forgot.) Your example helped immensely.

When importing text to the database the Total Hit counter really starts spinning - reminds me of a pinball game I used to play...