Jump to content
The Uniform Server Community

querying sqlite3 database


Bill King
 Share

Recommended Posts

Have been investigating alternative method to query a sqlite3 database using tclsh84 ...

 

Initially, I have installed on my PC(s) - tcl/tk(8.4.12.0). Also, have installed the

tclsqlite3 dll. I have multiple (simple) sqlite3 databases which I maintain on my PC(s)

and one on the USB stick. The premise was not to rewrite code in PHP (not a PHP guru)

and to utilize and modify existing tcl code to query several simple sqlite3 databases...

I was not prepared to download more extensions/update PHP etc. at this time.

 

Here is synopsis of this investigation (after various iterations):

 

1. Created a searchit.html file with a form (action=post) to pass information to searchit.php:

note: pass the database name/table/field to query and the search string.

 

2. With searchit.php I utilized the $_POST[""] (PHP array?) to make the variables that I wanted to

pass to the tclsh84 (tcl shell).

ie. $searchstring =$_POST["searchstring"]; etc.

 

Built and printed initial HTML code (headers etc.)

 

I then made a call to "tclsh84" and passed (script name: searchit.tcl) and variables to

query a database:

ie. $output = exec("tclsh84 searchit.tcl $database $table $entry $searchstring");

 

3. tclsh84 opens the script (searchit.tcl) and reads in the variables - loads tclsqlite3 and performs

the query (as coded in searchit.tcl script). This builds a variable that I called "page" to return to

searchit.php.

note: variable "page" is 1 string (containing results with HTML code in order to build a table as

well as highlight the search string(color red) in textual results etc. )

 

4. The searchit.php script then prints the information received ($output) from tclsh84

ie. print $output;

 

The searchit.php script then prints out final HTML code and new html page produced.

 

Lessons learned:

1. PHP - likes 1 string (with no breaks/newlines) returned from calls

and remember those ";'s" in PHP.

2. I thought this approach would bog down; but Uniform Server proved to be pretty

quick. I am impressed with speed on this old PC.

3. Unfortunately this would limit sqlite3 queries to those systems with tcl/tk installed;

however, for my purposes this works well....

4. Considering using this same approach using Python......

 

Cheers!

wjk

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...