Tag: sqlite3

如何将数据保存在iphone中的sqlite3

我想创build数据库使用SQLite的经理。但值不存储在数据库中。如果我点击保存button警报消息将显示在这样的“数据插入失败”。我试图纠正这些问题。这种情况下,我访问了这么多的教程。但我无法纠正我的问题。昨天起,我完全阻止这个问题。请给我任何想法或build议如何保存数据。谢谢大家访问的问题。 DataBase.m //创buildDATABASE -(BOOL)createDB { NSString *docsDir; NSArray *dirPaths; // Get the document directory dirPaths=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); docsDir=dirPaths[0]; // Build the path to the database file databasePath=[[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent:@"Feedback.db"]]; BOOL isSuccess=YES; NSFileManager *fileManager=[NSFileManager defaultManager]; if([fileManager fileExistsAtPath:databasePath]==0) { const char *dbpath=[databasePath UTF8String]; if(sqlite3_open(dbpath, &database)==SQLITE_OK) { char *errMsg; const char *sql_stmt= "create table if not exists Feeback […]

Sqlite3更新查询不工作在iOS应用程序

我试图更新我的表的列之一button点击。 问题是代码没有给出任何exception,但它不更新表。 当视图控制器再次加载时,它显示旧值而不是更新一个。 代码更新数据库附在下面。 @try { if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { NSString *sqlStatement = @"UPDATE messagesTable SET Favorite = 1 where MessageID="; sqlStatement = [sqlStatement stringByAppendingString:msgId]; NSLog(@"sql statement: %@", sqlStatement); const char *sql = [sqlStatement UTF8String]; int result = sqlite3_prepare_v2(database, sql, -1, &compiledStatement, NULL); if(result != SQLITE_OK) { NSLog(@"Prepare-error #%i: %s", result, sqlite3_errmsg(database)); } […]

iOS应用程序中的SQLite C函数导致EXC_BAD_ACCESS

在iOS应用程序中,我试图从100万行的表中的SQLite字段中去除变音符号。 编辑 : 我引用的原始答案已由其作者更新以反映下面接受的答案。 对于任何想要做同样事情的人来说,这是最好的答案。 Rob从早些时候的回答中得到了一个很好的开始。 对于这个问题,我试图复制一个表到另一个使用INSERT INTO … SELECT … FROM …语句。 这工作正常,直到我引入一个C函数,从字段中去除重音和其他变音符号: INSERT INTO DestinationTable (MasterField, SubField, IndexID) SELECT unaccented(MasterField), SubField, IndexID FROM SourceTable 随着unaccented()函数的介绍,我经常会得到一个EXC_BAD_ACCESS,我将在下面指定。 但令人震惊的是,SQLite操作有时会成功完成所有100万行 。 当我扩展负载以复制500万行时,应用程序将始终崩溃。 TL; DR 这里是我的源代码,EXC_BAD_ACCESS指向第一个函数的底部: #import <sqlite3.h> sqlite3 *db; void unaccented(sqlite3_context *context, int argc, sqlite3_value **argv) { if (argc != 1 || sqlite3_value_type(argv[0]) != SQLITE_TEXT) { sqlite3_result_null(context); […]

在iOS应用程序中实现sqlite3_busy_timeout()

我有一个使用Sqlite3作为数据库的iOS应用程序。 该应用程序是multithreading。 我想确保应用程序不会从一个线程获取SQlite数据locking到另一个线程。 我认为sqlite3_busy_timeout()可能是答案。 我的问题是我在哪里把sqlite3_busy_timeout()? 我在appdelegate中打开连接到sqlite。 我应该在打开sqlite连接之后立即将sqlite3_busy_timeout()放入,或者每次执行数据调用时都需要放入sqlite3_busy_timeout()。 感谢你的帮助。

iOS中Bundle资源的Sqlite3

您好我打算从我的项目资源文件夹中添加一个静态的SQLite3,但我不知道我是否正确地做到这一点。 到目前为止,这是我的进步…从SQLite数据库浏览器创buildSQLite3数据库 复制Sqlite3数据库到我的项目文件夹 将network.db添加到我的项目资源文件夹 现在我不知道下一步该去哪里..我希望有人能帮我解决我的问题。

未定义的符号体系结构i386使用libsqlite3.dylib与FMDB Xcode 7 ios9

我正在使用Xcode 7和iOS 9创build一个简单的应用程序,它保存数据并使用sqllite3检索它。 不过,使用libsqlite3.dylib库和从github获取的FMDB构build应用程序时,我收到以下错误消息。 Undefined symbols for architecture i386: "_sqlite3_bind_blob", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_bind_double", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_bind_int", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_bind_int64", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_bind_null", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_bind_parameter_count", referenced from: -[FMDatabase executeQuery:withArgumentsInArray:orDictionary:orVAList:] in FMDatabase.o -[FMDatabase executeUpdate:error:withArgumentsInArray:orDictionary:orVAList:] in FMDatabase.o […]

使用iOS应用程序中的现有数据

我很新的iOS开发,绝对不能完全理解Xcode和东西的工作。 我正在创build一个iOS应用程序,并已经使用Sqlite在设备上存储数据。 我已经添加了一个sqlite3数据库的项目,但我注意到,在模拟器中的数据库不存在的第一次运行的应用程序,因此必须在代码中创build。 到现在为止还好。 我应该有一个应用程序随附的date列表。 第一次运行时,应用程序是否可以使用已经有数据的数据库?

iOS – SQLite插入不插入数据

– (id)init { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"idataBase.sqlite3"]; NSLog(@"Doc path: %@",databasePath); bool databaseAlreadyExists = [[NSFileManager defaultManager] fileExistsAtPath:databasePath]; if (!databaseAlreadyExists){ NSString *databasePathFromApp = [[NSBundle mainBundle] pathForResource:@"idataBase" ofType:@"sqlite3"]; NSLog(@"Main bundle path: %@",databasePathFromApp); [[NSFileManager defaultManager] copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; } if (sqlite3_open([databasePath UTF8String], &_database) == SQLITE_OK){ NSLog(@"Database opened"); […]

将NSString转换为UTF8String时出错

-(id)select:(NSString *)original_query { sqlite3_stmt *statement; const char * converted = [original_query UTF8String]; NSLog(@"[INFO] converted char = %@", converted); if (sqlite3_prepare_v2(db, converted, -1, &statement, NULL) != SQLITE_OK) { @throw [NSException exceptionWithName: @"DB Encriptor" reason: [NSString stringWithFormat: @"Query \"%s\" has failed, we could not execute the SQL statement. '%s'", converted, sqlite3_errmsg(db) ] userInfo: nil]; } else { […]

在iPhone上的Sqlite“近”语法错误

我在我的iphone应用程序中用sqlite试验一个问题。 阅读部分是好的,但是当我尝试写入数据库使用UPADATE命令(我也尝试使用INSERT),sql语句给我回错误sqlite3_errmsg: Failed. Error is: near "UP": syntax error 代码是: -(void)ratesInfotoDb:(NSString *)idx rate:(NSString*)rate{ query =@"UPDATE rules set rate = 5 where _id = 1994"; sqlite3_stmt *statement; sqlite3_prepare_v2(_database, [query UTF8String], SQLITE_OPEN_READWRITE, &statement, nil); if(sqlite3_step(statement) == SQLITE_DONE ) { NSLog(@"element added"); } else{ NSLog( @"Failed. Error is: %s", sqlite3_errmsg(_database)); } sqlite3_finalize(statement); sqlite3_close(_database); } 查询命令“UPDATE rules set rate […]