title: Sqlite UPDATE question
body: <p>Hi i'm writing an iphone application that requires sqlite and one update query. So simply,why this works:</p>
  
  <pre><code>NSString *query=[NSString stringWithFormat:@"%@%@%@%@%@",
      @"UPDATE ZTABELLA SET ZTYPE =",@"1",
      @" WHERE ZNAME='",@"stringaoggetto",@"';"];
  
  sqlite3_exec(database2, [query UTF8String], NULL, NULL, NULL);  
  </code></pre>
  
  <p>and why this doesn't works:</p>
  
  <pre><code>NSString *query=[NSString stringWithFormat:@"%@%@%@%@%@",
      @"UPDATE ZTABELLA SET ZTYPE =",@"1",
      @" WHERE ZNAME='",oggetto,@"';"];
  
  sqlite3_exec(database2, [query UTF8String], NULL, NULL, NULL);  
  </code></pre>
  
  <p>The difference between this two examples is only <code>@"stringaoggetto"</code> in the first and <code>oggetto</code> in the second. In the first i have inserted value directly with a string,in the second example <code>oggetto</code> is a nsstring object that have the right value inside (i have printed a nslog). Why this difference?   </p>
  
  <p>The log for query is the same for each example:</p>
  
  <pre><code>NSLog(@" %@",query);
  //this log print: UPDATE ZTABELLA SET ZTYPE =1 WHERE ZNAME='stringaoggetto';
  </code></pre>
  
  <p>The log for the nsstring object "oggetto" is:</p>
  
  <pre><code>NSLog(@"%@",oggetto);
  //this log print   stringaoggetto
  </code></pre>
  
  <p>I have also tried another code to check the error,but the result is the same:</p>
  
  <pre><code>if (sqlite3_open([dbPath2 UTF8String], &amp;database2) == SQLITE_OK) {
  
  
        const char *update = "UPDATE ZTABELLA SET ZTYPE =1 WHERE ZNAME=?";
  
        sqlite3_stmt *updatestmt;
  if(sqlite3_prepare_v2(database2, update, -1, &amp;updatestmt, NULL) == SQLITE_OK) {
  
  sqlite3_bind_text(updatestmt, 1, [oggetto UTF8String] , -1, SQLITE_TRANSIENT);
  
  
  if(SQLITE_DONE != sqlite3_step(updatestmt)){
  
      NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database2));
  
                  }
  sqlite3_reset(updatestmt);                  
  
              }
              else {
                  NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database2));
  
              }
              }
  </code></pre>
  
  <p>As the first direct query (with sqlite3_exc) in this case the sqlite3_bind_text doesn't works after where clause. With the same query if i try for testing purpose to set column ZTYPE insted of ZNAME (however any other column can't be set "Where") it works. Why?</p>
  
  <p>This is the init of the nsstring oggetto,is the result of select query:</p>
  
  <pre><code>NSMutableString *oggetto;
  oggetto=[NSString stringWithCString:(char *)sqlite3_column_text(selectstmt, 0)];
  </code></pre>
  
  <p>this string retain correctly the value (the value is "stringaoggetto"),i have tried with a nslog. </p>