Note that there are some explanatory texts on larger screens.

plurals
  1. POsqlite c++ program values get inserted only first time second time they don't
    primarykey
    data
    text
    <p>when i try to insert values everything works fine for the first time but second time it doesn't take values,what should i do.? after creating table i try to insert values which works fine,now second time again if i try to insert it doesn't take values also when i want to select it is only displaying 1st column that is user id but i want the whole column to be displayed</p> <pre><code> #include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;iostream&gt; #include &lt;sstream&gt; #include &lt;string&gt; using namespace std; #include "sqlite3.h" int main (int argc, const char * argv[]) { int ch; int userid; string name; string sName; int rc; sqlite3 *db; sqlite3_open("custom1.db", &amp; db); string createQuery = "CREATE TABLE IF NOT EXISTS items3 (uid INTEGER primary key ,name TEXT);"; std::stringstream insertQuery; std::stringstream selectQuery; std::stringstream removeQuery; while(ch!=5){ cout&lt;&lt;endl&lt;&lt;"1:create table"&lt;&lt;endl&lt;&lt;"2:insert data"&lt;&lt;endl&lt;&lt;"3:select data"&lt;&lt;endl&lt;&lt;"4:remove"&lt;&lt;endl&lt;&lt;"5:exit"&lt;&lt;endl; cout&lt;&lt;"enter choice"&lt;&lt;endl; cin&gt;&gt;ch; switch(ch) { case 1 : sqlite3_stmt *createStmt; cout &lt;&lt; "Creating Table Statement" &lt;&lt; endl; sqlite3_prepare(db, createQuery.c_str(), createQuery.size(), &amp;createStmt, NULL); cout &lt;&lt; "Stepping Table Statement" &lt;&lt; endl; if (sqlite3_step(createStmt) != SQLITE_DONE) cout &lt;&lt; "Didn't Create Table!" &lt;&lt; endl; break; case 2 : sqlite3_stmt *insertStmt; cout &lt;&lt; "Creating Insert Statement" &lt;&lt; endl; cout&lt;&lt;"userid:";cin&gt;&gt;userid;cout&lt;&lt;"name:";cin&gt;&gt;name; insertQuery &lt;&lt; "INSERT INTO items3 (uid,name)" " VALUES (" &lt;&lt; userid &lt;&lt; ", '" &lt;&lt; name&lt;&lt;"')"; sqlite3_prepare(db, insertQuery.str().c_str(), insertQuery.str().size(), &amp;insertStmt, NULL); cout &lt;&lt; "Stepping Insert Statement" &lt;&lt; endl; if (sqlite3_step(insertStmt) != SQLITE_DONE) cout &lt;&lt; "Didn't Insert Item!" &lt;&lt; endl; sqlite3_reset(insertStmt); sqlite3_close(db); break; case 3: sqlite3_stmt *selectStmt; cout &lt;&lt; "Creating select Statement" &lt;&lt; endl; cout&lt;&lt;"userid:"; cin&gt;&gt;userid; selectQuery&lt;&lt;"select * from items3 where uid="&lt;&lt;userid; rc= sqlite3_prepare(db, selectQuery.str().c_str(), selectQuery.str().size(), &amp;selectStmt, NULL); cout &lt;&lt; "Stepping select Statement" &lt;&lt; endl; while (sqlite3_step(selectStmt) == SQLITE_ROW) { sName = (char*)sqlite3_column_text(selectStmt, 0); // Obj.Display(sName); //&lt;== this is not display cout &lt;&lt; "userid" &lt;&lt; sName &lt;&lt; endl; } sqlite3_step(selectStmt); if (sqlite3_step(selectStmt) != SQLITE_DONE) cout &lt;&lt; "Didn't Select Item!" &lt;&lt; endl; else cout &lt;&lt; "Success!" &lt;&lt; endl; sqlite3_close(db); break; case 4 :sqlite3_stmt *removeStmt; cout&lt;&lt;"creating remove statement"&lt;&lt;endl; cout&lt;&lt;"userid:"; cin&gt;&gt;userid; removeQuery&lt;&lt;"delete from items3 where uid="&lt;&lt;userid; sqlite3_prepare(db,removeQuery.str().c_str(),removeQuery.str().size(),&amp;removeStmt,NULL); cout&lt;&lt;"stepping remove statement"&lt;&lt;endl; if(sqlite3_step(removeStmt)!=SQLITE_DONE) cout&lt;&lt;"didn't remove item!"&lt;&lt;endl; else cout&lt;&lt;"success"&lt;&lt;endl; sqlite3_close(db); break; } } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload