Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2006
    Location
    Japan
    Posts
    21

    Huh? SQLite count number of table rows

    Hi all, VERY lame question I'm sure, but I've finally given up.

    Basically all I want to do is count the number of rows in my SQLite table. Sounds very simple.

    Code:
    sql = "select count(*) from territories";
    tbResults = SQLite.QueryToTable(db, sql);
    max_rows = Table.Concat(tbResults, "", 1, TABLE_ALL);
    
    Paragraph.SetText("Paragraph1", "The query took " .. hours.. " hrs " .. mins .. " mins "..secs.." secs. \nIt returned " .. no_rows .. " rows. \n" .. max_rows .. " rows imported into SQLite")
    Can anyone please suggest why I have an error "SQL logic error or missing database"?

    What I'm doing in AMS (and this part is working), is;

    a) Connect to Oracle Applications, use Oracle SQL to retrieve data from database to text file (yuk, but there's no direct SQLite to Oracle method I know of....)

    b) Load that text file (yuk again) into SQLite in AMS

    c) give the user a message like "244 rows imported into SQLite"

    Sounds soooo simple...

    Thanks in advance
    Andy

  2. #2
    Join Date
    Oct 2004
    Location
    East, South & West Asia
    Posts
    1,020
    Hi,

    SQL logic error is caused by wrong sql syntax.

    To count number of rows you read to a table, the value for the number of rows is in TableName.Rows.

    eg.

    nRows = tbResults.Rows; -- you'll get the number of rows
    Newbie Examples
    ------> AMS 7.5 : amstudio.azman.info
    ----> AMS 6 & 5: www.azman.info/ams/
    ----> FB: facebook.com/GuideToWealth

    ----> Content Development Blog: www.AZMAN.asia

  3. #3
    Join Date
    Jul 2006
    Location
    Japan
    Posts
    21

    Cool Thank you. However...

    Thanks for the quick reply azmanar.

    I've corrected the code as below, the answer it is giving me is perfect however I still get the error message when AMS is evaluating the sql...

    "SQL logic error or missing database"

    Code:
    tbResultsx = SQLite.QueryToTable(db, "select * from territories");
    nRowsx = tbResultsx.Rows;
    
    Paragraph.SetText("Paragraph1", "The query took " .. hours.. " hrs " .. mins .. " mins "..secs.." secs. \nIt returned " .. file_to_table_rows .. " rows. \n" .. nRowsx .. " rows imported into SQLite")
    Any suggestions how to stop the error from appearing...?

    In addition, having to load the whole record set into memory seems like an amazing waste of processing time. In Oracle SQL, you can just do "select count (1) from territories" and the results are returned very quickly even on large tables. From what I can see here, we need to scan the entire record set into memory.... freaky.....

    Thanks
    Andy

  4. #4
    Join Date
    Oct 2004
    Location
    East, South & West Asia
    Posts
    1,020
    Hi,

    I've never used Oracle before but I've been using SQLite and MySQL.

    At my side, usually this error occurs if the SQL syntax is erroneous.

    While if the SQL DB handle is not created correctly and not opened before using this query "SQLite.QueryToTable(db, "select * from territories");", it won't even count the rows you have.

    There could be some other explanation for the error you're having. Probably Worm, Tigger, Shadow, Dermot, Reteset, Bule or Longedge could help.
    Newbie Examples
    ------> AMS 7.5 : amstudio.azman.info
    ----> AMS 6 & 5: www.azman.info/ams/
    ----> FB: facebook.com/GuideToWealth

    ----> Content Development Blog: www.AZMAN.asia

  5. #5
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    COUNT(*) works fine. Try this.
    Code:
    local sql = "SELECT COUNT(*) AS Total FROM territories";
    local tbResults = SQLite.QueryToTable(db, sql);
    local max_rows = tbResults.Data[1]["Total"]
    Dialog.Message("Record Count", max_rows)
    If you are still getting the error then something else is wrong. Maybe post a test database so we can try it.
    Dermot

    I am so out of here

  6. #6
    Join Date
    Jul 2006
    Location
    Japan
    Posts
    21

    Sample database uploaded...

    Dermot/azmanar,

    Thanks for your advice, however I'm still getting this freaky error. Can you please take a look at the uploaded database.

    Simply put the text file into the C:\ directory and press the button and all should run. You will see the freaky "SQL logic error or missing database" error just near the end of the button script.



    Thanks in advance.
    Andy

    P.S. It tells you that it is processing 244 records when there are only 237 in the file... I also don't get that either...
    Attached Files
    Last edited by Shide; 03-25-2009 at 11:20 PM. Reason: Additional Information

  7. #7
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    Actually the text file has 244 records. The error is not from the count(*). The problem is your text file. There is a blank line at the end of the file, that's why it tells you the text file has 245 records. Remove the blank line and you get no error.
    Dermot

    I am so out of here

  8. #8
    Join Date
    Jul 2006
    Location
    Japan
    Posts
    21

    Solved "SQL logic error or missing database"



    Dermot, thank you for that. I've modified the program that exports the data to the file without the trailing chr(34). newbie mistake that one.

    Much appreciated.
    Andy

Similar Threads

  1. Including CrystalReport VS2005
    By Calisana in forum MSI Factory 2.0 Discussion
    Replies: 3
    Last Post: 03-17-2009, 09:28 AM
  2. SQLite won't Alter Table
    By pjborg in forum AutoPlay Media Studio 7.5
    Replies: 10
    Last Post: 06-28-2008, 08:59 AM
  3. SQLite Table Joins
    By azmanar in forum AutoPlay Media Studio 6.0
    Replies: 5
    Last Post: 01-11-2006, 11:16 AM
  4. SQLite – Column names and number of columns
    By csd214 in forum AutoPlay Media Studio 5.0
    Replies: 7
    Last Post: 08-17-2004, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts