For Programmers: Free Programming Magazines  


Home > Archive > Tcl > September 2005 > Direct connection to databases









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Direct connection to databases
Silas Justiniano

2005-09-21, 9:57 pm

Hello all!

I'm doing an interesting application for a book store. I'll use MySQL
and SQLite. The problem is I don't know how to make a direct connection
to the database.

Connect, query and retrieve data is not problem for me. I can query a
lot the database and retrieve many information. But when I was on
Windows (fortunatelly, I'm not there anymore) I saw some IDEs like
Delphi and VB (argh!) have made direct connection to the database file.
For example, I have a table called mytable.px (px: Paradox Format (I
hate this)). In Delphi I could change some properties and then I've got
a direct connection to the database. With some code I could type
something in a TEdit (an entry) that in the same time, the record I
want would show up.

In Tcl, I could:

set result [sql query "SELECT mycolumn FROM mytable"]; #se there is no
WHERE

I just want to allow the user see the information while he/she types
the word in a textbox. While he/she types, a listbox content is
changed, localizing at realtime the item he/she wants.

The problem is: imagine I have 10 Gb of information!!! I just can't
retrieve this data.

Is it possible to make something like Delphi does in Windows?

Do you know something?

Thank you very much... Bye!

Leopold Gerlinger

2005-09-22, 3:58 am

Sorry - I have no hint for accessing a DB file but I wonder how Delphi
should be
able in "real-time" (I associate you mean very fast) to scan a 10GB file for
some
pattern a user types into an entry field???

Your problem is definitely not Windows/*NIX or accessing the DB vs. a file
but
simply the sheer amount of data you have.

Regards - Leo


Silas Justiniano

2005-09-22, 7:00 pm

I don't think it reads all the data and put it in the RAM. While you
scroll the grid where data appears, you can see there is delay. I
suppose it reads the information directly from the file.

Michael A. Cleverly

2005-09-22, 9:58 pm

On Wed, 21 Sep 2005, Silas Justiniano wrote:

> I'm doing an interesting application for a book store. I'll use MySQL
> and SQLite. The problem is I don't know how to make a direct connection
> to the database.


You need to load an extension ("package require tclsqlite"), at a minimum.
When you say you'll use MySQL and SQLite, do you mean you're application
is being written to support either, or that to function properly it will
have to talk to both simultaneously?

> Connect, query and retrieve data is not problem for me. I can query a
> lot the database and retrieve many information. But when I was on
> Windows (fortunatelly, I'm not there anymore) I saw some IDEs like
> Delphi and VB (argh!) have made direct connection to the database file.
> For example, I have a table called mytable.px (px: Paradox Format (I
> hate this)). In Delphi I could change some properties and then I've got
> a direct connection to the database. With some code I could type
> something in a TEdit (an entry) that in the same time, the record I
> want would show up.
>
> In Tcl, I could:
>
> set result [sql query "SELECT mycolumn FROM mytable"]; #se there is no
> WHERE
>
> I just want to allow the user see the information while he/she types
> the word in a textbox. While he/she types, a listbox content is
> changed, localizing at realtime the item he/she wants.


Since you're building a GUI you'll be using Tk. You'll want an entry
widget to allow the user to type in, and a listbox to show X number of
rows.

Use the [bind] command to bind a proc to the entry widget (or use the
entry widgets validation option to call a proc when the value in the entry
field changes, see http://wiki.tcl.tk/768).

Then have a proc that queries the database for X number of rows (certainly
not all rows!) that match what the user has entered. With tclsqlite,
assuming your database handle is db, you could do:

set listbox_contents [db eval "select mycolumn from mytable where myfield
like '$myfield%' order by mycolumn limit 20"]


> The problem is: imagine I have 10 Gb of information!!! I just can't
> retrieve this data.


That's why you only would want to retrieve enough to fill the current
screen.

> Is it possible to make something like Delphi does in Windows?
>
> Do you know something?
>
> Thank you very much... Bye!


Michael
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com