Note that there are some explanatory texts on larger screens.

plurals
  1. POValues storing 2 times in database
    text
    copied!<p>I have to insert x &amp; y touch coordinates values in database. But it storing 2 times in database. When i long press i'm getting touch coordinates and insert some tag for button_tag. But i longpress once, why the values are storing 2 times</p> <p>Table:</p> <pre><code>button_tag xcoor ycoor 2 123.5 320.9 23 123.5 320.9 - (void)tapTest:(UILongPressGestureRecognizer *)sender { NSLog(@"coordinate is %f %f", [sender locationInView:wbCont.scrollView].x, [sender locationInView:wbCont.scrollView].y); xcor = [sender locationInView:wbCont.scrollView].x; ycor = [sender locationInView:wbCont.scrollView].y; universal_button_tag = arc4random() % 99; NSLog(@"Universal Button tag: %d",universal_button_tag); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"db.sqlite"]; NSLog(@"filepath %@",path); if (sqlite3_open([path UTF8String], &amp;database) == SQLITE_OK) { const char *sql = [[NSString stringWithFormat:@"SELECT button_tag,xcoor,ycoor FROM touch where button_tag='%d' AND xcoor = '%f' AND ycoor = '%f'",universal_button_tag,xcor,ycor] cStringUsingEncoding:NSUTF8StringEncoding]; NSLog(@"sql is %s",sql); BOOL favExist = false; sqlite3_stmt *statement, *addStmt; if (sqlite3_prepare_v2(database, sql, -1, &amp;statement, NULL) == SQLITE_OK) { // We "step" through the results - once for each row. while (sqlite3_step(statement) == SQLITE_ROW) { favExist = true; } } if(!favExist){ //Changes const char *sqlInsert = [[NSString stringWithFormat:@"insert into touch (button_tag,xcoor,ycoor) values ('%d','%f','%f')", universal_button_tag,xcor,ycor] cStringUsingEncoding:NSUTF8StringEncoding]; //---- NSLog(@"sql insert is %s",sqlInsert); // [catID release]; if(sqlite3_prepare_v2(database, sqlInsert, -1, &amp;addStmt, NULL) != SQLITE_OK) NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database)); NSLog(@"error is %s",sqlite3_errmsg(database)); if(SQLITE_DONE != sqlite3_step(addStmt)) NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database)); } } } </code></pre>
 

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