Sign in to follow this  
Followers 0
krishpun

Unable to fetch data

10 posts in this topic

I am unable to fetch data from sqlite database.

Not sure where I am faulting.

Please check the attached file "table.jpg" for a snapshot of the database and the table.

A)

Below is the error.

! SQLite.au3 Error

--> Function: _SQLite_Query

--> Query: SELECT name from Main.Admission_details where admitno = '122A';

--> Error: no such table: Main.Admission_details

:unsure:

Even if I pass non existent db file name for the below variable, it is returning some handle number

$sdb="d:\MIS\MISdata123434.db"

$dbh=_SQLite_Open ($sdb)

According to help, it is suppose to return 0 for the above code.

C)

I am trying to fetch here a data from the table.

#include <SQLite.au3>

#include <SQLite.dll.au3>

Local $sSQliteDll, $hQuery, $aRow, $aNames

Local $sDatabase_Filename

$sSQliteDll = _SQLite_Startup ()

_SQLite_Startup()

$sdb="d:\MIS\MISdata.db"

$dbh=_SQLite_Open ($sdb)

_SQlite_Query ($dbh, "SELECT name from Main.Admission_details where admitno = '122A';", $hQuery)

_SQLite_FetchData ($hQuery, $aRow, False, False)

MsgBox(1,"dfd",$aRow[0])

This msgbox is returning nothing.

Please help.

post-62315-0-32671100-1302700301_thumb.j

Share this post


Link to post
Share on other sites



A )

Just what the error says...

--> Error: no such table: Main.Admission_details

Looking at the screenshot I'll assume you should try something like:

"SELECT name from Admission_details where admitno = '122A';"

B )

You're right. Seems like the dll function "sqlite3_open_v2" itself checks for existence of the db file, and if it does not find it, it just opens a memory DB.

C )

see A) :unsure:

Share this post


Link to post
Share on other sites

I second the idea of trying the query without the prepended "Main."

Share this post


Link to post
Share on other sites

I tried what you have suggested ie...

SELECT admitno from Admission_details where admitno = '122A';"

But still no luck.

Could you check the attachment I had uploaded earlier.

One more thing...

Please check the file I have attached now

.databases does not list the "d:\MIS\MISdata.db" database.

Why? Is it because of this, iam unable to get the result.

Please help.

post-62315-0-24151300-1302702447_thumb.j

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Still No luck.

I think it is unable to identify the table itself.

! SQLite.au3 Error

--> Function: _SQLite_Query

--> Query: SELECT name from Admission_details where admitno like '122A';

--> Error: no such table: Admission_details

Edited by krishpun

Share this post


Link to post
Share on other sites

This is a bit of code I'm using successfully:

_SQLite_Startup()

                Local $aResult, $iRows, $iColumns
                _SQLite_Open(@ScriptDir & "\gp.sqlite")
                If @error Then
                    MsgBox(16, "SQLite Error", "Can't Load Database!")

                EndIf

                $sSQL = "SELECT GPcode, GPname, GPsurgery, GPadd1, GPadd2, GPadd3, GPadd4  FROM GPs WHERE GPname LIKE '% " & $GPquery & "%'"

                Local $get = _SQLite_GetTable2d(-1, $sSQL, $aResult, $iRows, $iColumns)


_SQLite_Close()

                _SQLite_Shutdown()

Is the comma after 122A causing the problem?

William

PS I assume you're in healthcare computing - I hope the patient names in your screenshot are made-up ones?!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

"SELECT admitno from Main.Admission_details where admitno like '122A';"

Edit:

Can't delete post, but statement's the same as in your first post :unsure:.

Maybe try this to query tables:

"SELECT name FROM sqlite_master WHERE type = 'table';"

Edited by KaFu

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

You must be missing something else, elsewhere in your actual code.

Here's why: I created a fake MISdata.db database and inserted the two first rows (partial).

You example code works (in the first post, with the Main. table qualifier) and produces the correct result.

It works identically (unsurprinsingly) without the Main. table qualifier.

How are you checking for error returns after _SQLite_* calls?

BTW you should not call _SQLite_Startup twice.

Regarding your question 2), yes, openv2 opens a default :memory: DB if no parameter is given, or if the file passed as parameter doesn't exist, then it will create one.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Thanks to all for your inputs.I could identify the problem.

It was because, I had created the database using the sqlite developer utility and it gets created as a file without .db extension (MISdata)

Where as, the one created using _SQLite_Open function creates the db correctly with the file name suffixed by .db

(MISdata.db)

Now, the same code is working fine.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0