krishpun Posted April 13, 2011 Share Posted April 13, 2011 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_detailsEven 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, $aNamesLocal $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. Link to comment Share on other sites More sharing options...
KaFu Posted April 13, 2011 Share Posted April 13, 2011 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) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
smartee Posted April 13, 2011 Share Posted April 13, 2011 I second the idea of trying the query without the prepended "Main." Link to comment Share on other sites More sharing options...
krishpun Posted April 13, 2011 Author Share Posted April 13, 2011 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. Link to comment Share on other sites More sharing options...
KaFu Posted April 13, 2011 Share Posted April 13, 2011 Maybe try: "SELECT admitno from Admission_details where admitno like '122A';" OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
krishpun Posted April 13, 2011 Author Share Posted April 13, 2011 (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 April 13, 2011 by krishpun Link to comment Share on other sites More sharing options...
saywell Posted April 13, 2011 Share Posted April 13, 2011 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?! Link to comment Share on other sites More sharing options...
KaFu Posted April 13, 2011 Share Posted April 13, 2011 (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 . Maybe try this to query tables: "SELECT name FROM sqlite_master WHERE type = 'table';" Edited April 13, 2011 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
jchd Posted April 13, 2011 Share Posted April 13, 2011 (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 April 13, 2011 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 hereRegExp tutorial: enough to get startedPCRE 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) Link to comment Share on other sites More sharing options...
krishpun Posted April 14, 2011 Author Share Posted April 14, 2011 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now