|
|
|
iOS - Insert SQLite 3 error "library routine called out of sequence" ใครเคยเจอบ้างครับ |
|
|
|
|
|
|
|
Error "library routine called out of sequence" ตอน เพิ่มข้อมูล
Code (Objective-C)
-(void)SaveRecvInvoice
{
NSString *docDIR;
NSArray *dirPath;
dirPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docDIR = dirPath[0];
_databasePath = [[NSString alloc] initWithString:[docDIR stringByAppendingPathComponent:@"consign.db"]];
sqlite3_stmt *statement = NULL;
const char *dbpath = [_databasePath UTF8String]; //กำหนดรูปเเบบเป็น UTF8
if (sqlite3_open(dbpath, &_DB) == SQLITE_OK)
{
//วันที่ปัจจุบัน
NSDateFormatter *DateFormatter = [[NSDateFormatter alloc]init];
[DateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *nowDate = [NSString stringWithFormat:@"%@",[DateFormatter stringFromDate:[NSDate date]]];
for(id obj in myObject)
{
NSString *invoice_id = [obj objectForKey:@"Inv"];
NSString *strBar = [obj objectForKey:@"Bar"];
NSString *strModel = [obj objectForKey:@"Procode"];
NSString *strSize = [obj objectForKey:@"Size"];
NSString *color_id = [obj objectForKey:@"Colorcode"];
NSString *color = [obj objectForKey:@"Desc"];
NSString *strPrice = [obj objectForKey:@"Price"];
NSString *strQtys = [obj objectForKey:@"Qty"];
NSString *strDisc = [obj objectForKey:@"Disc"];
NSString *strAmt = [obj objectForKey:@"Amt"];
NSString *us = [self QueryUser];
NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO recivedInv (user, docno, recvdate, barcode, prodcode, colorcode, desc, size, qty, price, dicper, amt, last_date) VALUES (\"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\",\"%@\",\"%@\", \"%@\",\"%@\", \"%@\", \"%@\", \"%@\")",us, invoice_id, nowDate, strBar, strModel, color_id, color, strSize, strQtys, strPrice, strDisc, strAmt, nowDate];
const char *insert_statement = [insertSQL UTF8String];
sqlite3_prepare_v2(_DB, insert_statement, -1, &statement, NULL);
if (sqlite3_step(statement) != SQLITE_DONE)
{
[self showUIAlertWithMessage:@"Failed to add sqlite database" andTitle:@"Error"];
NSLog( @"Failed from sqlite3_step. Error is: %s", sqlite3_errmsg(_DB));
}
}
sqlite3_finalize(statement);
sqlite3_close(_DB);
}
}
Tag : Mobile, Ms SQL Server 2008, iOS
|
|
|
|
|
|
Date :
2015-01-30 18:10:24 |
By :
junior_dev |
View :
1301 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (Objective-C)
sqlite3 *lDb;
sqlite3_stmt *lStmt;
NSNumberFormatter *lNbrFmt = [[[NSNumberFormatter alloc] init] autorelease];
// Define SQL statement
NSString *lSql = @"SELECT section, language, title, description"
@" selector-x-pos, selector-y-pos, gps-x-pos, gps-y-pos"
@" FROM sections"
@" ORDER BY section ASC";
if(sqlite3_open([[fileMethods databasePath] UTF8String], &lDb) == SQLITE_OK) {
lSqlResult = sqlite3_prepare_v2(lDb, [lSql UTF8String], -1, &lStmt, NULL);
NSLog(@"%@", [NSString stringWithUTF8String:sqlite3_errmsg(lDb)]);
ลองตัวนี้ดูครับ
|
|
|
|
|
Date :
2015-01-31 09:04:12 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|