Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3285544
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:16:44+00:00 2026-05-17T20:16:44+00:00

I have three queries that I’m running through SQLite. These are what I’m running;

  • 0

I have three queries that I’m running through SQLite. These are what I’m running; the first is the table declaration and then the next 3 are the actual queries.

Declaration:

“CREATE TABLE IF NOT EXISTS items (busid INTEGER PRIMARY KEY, ipaddr TEXT, time TEXT DEFAULT (NOW()));”

Queries:

  1. (Works) “INSERT INTO items (time, ipaddr) VALUES (‘test’, ‘192.168.1.1’);”
  2. (Crashes) “INSERT INTO items (busid, ipaddr) VALUES (10, ‘192.168.1.1’);”
  3. (Crashes) “INSERT INTO items (ipaddr) VALUES (‘192.168.1.1’);”

Query 1 works fine, whereas queries 2 and 3 cause a crash by means of an EXC_BAD_ACCESS within sqlite3ExprCodeTarget. Tracing back, I discover the last point my code touches is a sqlite3_prepare_v2() statement, which passes a valid database/string/etc. and, as I said, works fine with statement 1 above but not 2 or 3. What’s wrong with this, and how can I fix it? Thanks.

EDIT 1: To clarify, Query 1, 2, and 3 are run separately in different runs of the program, not in sequence, and the database is destroyed in between runs, so running Query 1 has no effect on running Query 2 after the reset.

EDIT 2: Example C++ source file showing issue:

#include <iostream>
using namespace std;
#include <sqlite3.h>

int main (int argc, const char * argv[]) {

    sqlite3 *db;
    sqlite3_open("/Users/Justin/Desktop/test.db", &db);

    string createQuery = "CREATE TABLE IF NOT EXISTS items (busid INTEGER PRIMARY KEY, ipaddr TEXT, time TEXT NOT NULL DEFAULT (NOW()));";
    sqlite3_stmt *createStmt;
    cout << "Creating Table Statement" << endl;
    sqlite3_prepare_v2(db, createQuery.c_str(), createQuery.size(), &createStmt, NULL);
    cout << "Stepping Table Statement" << endl;
    if (sqlite3_step(createStmt) != SQLITE_DONE) cout << "Didn't Create Table!" << endl;

    // COMMENT OUT UNUSED ONES
    // First one works, second and third ones fail.

    string insertQuery = "INSERT INTO items (time, ipaddr) VALUES ('test', '192.168.1.1');"; // WORKS!
    //string insertQuery = "INSERT INTO items (busid, ipaddr) VALUES (10, '192.168.1.1');"; // FAILS!
    //string insertQuery = "INSERT INTO items (ipaddr) VALUES ('192.168.1.1');"; // FAILS!

    sqlite3_stmt *insertStmt;
    cout << "Creating Insert Statement" << endl;
    sqlite3_prepare_v2(db, insertQuery.c_str(), insertQuery.size(), &insertStmt, NULL);
    cout << "Stepping Insert Statement" << endl;
    if (sqlite3_step(insertStmt) != SQLITE_DONE) cout << "Didn't Insert Item!" << endl;

    cout << "Success!" << endl;
}

Just set the database path in the source code to wherever you want it to create the test database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:16:44+00:00Added an answer on May 17, 2026 at 8:16 pm

    i downloaded your source, compiled and ran with each line uncommented in turn, all works ok

    sqlite version 3.6.23.1

    redhat 5 32 bit

    so i guess the answer is – upgrade to latest version of sqlite

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble with a query, the problem is that i am left joining
In my app, I have three models: Markets, Deals, and Users. Relationships are pretty
Back-Story On a current project, I am using MySQL and SQLite in combination with
I have a MySQL DB containing entry for pages of a website. Let's say
Does anyone know if it is possible to write a query that can produce
I'm fairly new to MySQL and don't know how to write a query I
I consider myself fairly competent in understanding and manipulating C-ish languages; it's not a
I am having noticing some performance issues on my MySQL Server. The slow query
I just got a list of requirements for a new search function for our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.