SQLite3 query fails, the error does not

naut92

SQLite3 query fails, the error does not.   Insert data in the database ok, but does not get the data, what is my fault?

 protected function db2Array($data){
    $arr = array();
    while ($row = $data -> fetchArray(\SQLITE3_ASSOC)){
            $arr[] = $row;
            }
    return $arr;
    }

function getNews() {
    try{
        $sql = "SELECT msgs.id as id, title, category.name as category, description, source, datetime
          FROM msgs, category
          WHERE category.id = msgs.category
          ORDER BY msgs.id DESC";
        $res = $this->_db -> query($sql);
        if(!is_object($res)){
        throw new Exception ($this->_db -> LastErrorMsg());
        return $this->db2Array($res);
        }
    } catch (Exception $exs){
        //$exs -> getMessage();
        return FALSE;
    }
}
Joachim Isaksson

Indenting the code a bit makes it a bit more clear;

if(!is_object($res)){
    throw new Exception ($this->_db -> LastErrorMsg());
    return $this->db2Array($res);  // This will never execute due to the throw
}

If there's an error, you throw an exception and then (in code that won't execute) return the result. If there is no error, you don't return anything.

You need to move the return outside the if scope;

if(!is_object($res)) {
    throw new Exception ($this->_db -> LastErrorMsg());
}
return $this->db2Array($res);

Now the code will throw an exception on error, and return a result otherwise.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

python sqlite3 query with AND

分類Dev

Issue integrating SQLITE3 date query into MYSQL

分類Dev

Rails 4 sql query interpretation with mysql or sqlite3

分類Dev

SQLite3 / PDO - No such table though it does exist

分類Dev

sqlite3 "OperationalError: near "(": syntax error" python

分類Dev

Error installing sqlite3, Failed to build gem native extension

分類Dev

sqlite3 raised an error after running Airflow command line

分類Dev

sqlite3 error: You did not supply a value for binding 1

分類Dev

configure error: Package requirements (sqlite3 > 3.7.4) were not met

分類Dev

Rails Server Gem Load Error - SQlite3

分類Dev

rake figaro:heroku is returning an error with sqlite3

分類Dev

Capybara error ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked

分類Dev

MySQL query does not run in SQLite

分類Dev

Java system command to load sqlite3 db from file fails

分類Dev

How can I get a user's rank/position in SQLite3 with a query?

分類Dev

django - post_save - Order matching query does not exist error

分類Dev

SCP fails without error

分類Dev

3 way left join query error

分類Dev

Error: Cannot find module \node_modules\sqlite3\lib\binding\electron-v8.0-win32-x64\node_sqlite3.node'

分類Dev

Athena query fails with boto3 (S3 location invalid)

分類Dev

Python:sqlite3

分類Dev

exit fails to set error code

分類Dev

Installing gems fails with timeout error

分類Dev

providedIn: LazyModule fails with no provider error

分類Dev

movefile() fails error 2 or 123

分類Dev

CREATE VIEW returns error "date does not match a defined type name", but the actual query runs normally

分類Dev

PHP function fails to connect to the database to call query

分類Dev

CoreDataとSQLite3

分類Dev

From Sqlite3 to Sqlalchemy

Related 関連記事

  1. 1

    python sqlite3 query with AND

  2. 2

    Issue integrating SQLITE3 date query into MYSQL

  3. 3

    Rails 4 sql query interpretation with mysql or sqlite3

  4. 4

    SQLite3 / PDO - No such table though it does exist

  5. 5

    sqlite3 "OperationalError: near "(": syntax error" python

  6. 6

    Error installing sqlite3, Failed to build gem native extension

  7. 7

    sqlite3 raised an error after running Airflow command line

  8. 8

    sqlite3 error: You did not supply a value for binding 1

  9. 9

    configure error: Package requirements (sqlite3 > 3.7.4) were not met

  10. 10

    Rails Server Gem Load Error - SQlite3

  11. 11

    rake figaro:heroku is returning an error with sqlite3

  12. 12

    Capybara error ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked

  13. 13

    MySQL query does not run in SQLite

  14. 14

    Java system command to load sqlite3 db from file fails

  15. 15

    How can I get a user's rank/position in SQLite3 with a query?

  16. 16

    django - post_save - Order matching query does not exist error

  17. 17

    SCP fails without error

  18. 18

    3 way left join query error

  19. 19

    Error: Cannot find module \node_modules\sqlite3\lib\binding\electron-v8.0-win32-x64\node_sqlite3.node'

  20. 20

    Athena query fails with boto3 (S3 location invalid)

  21. 21

    Python:sqlite3

  22. 22

    exit fails to set error code

  23. 23

    Installing gems fails with timeout error

  24. 24

    providedIn: LazyModule fails with no provider error

  25. 25

    movefile() fails error 2 or 123

  26. 26

    CREATE VIEW returns error "date does not match a defined type name", but the actual query runs normally

  27. 27

    PHP function fails to connect to the database to call query

  28. 28

    CoreDataとSQLite3

  29. 29

    From Sqlite3 to Sqlalchemy

ホットタグ

アーカイブ