Tag: sqlite

在Swift中导入和查询SQLite数据库 – iOS

我正在做一个应用程序,使用5个不同的表的大型数据库。 我想将该数据库导入到应用程序包并能够通过表查询。 数据库不会被用户编辑,因此不需要添加和删除logging。 什么是在应用程序中添加数据库的最佳方式?

用于多种语言的多个SQLite数据库?

我想为我的应用程序实现多语言支持。 所以我创build了Localizing.strings文件和所有这些东西,并翻译了我的界面。 到现在为止还挺好 … 现在我想复制我的数据库,以便为每种语言都有一个* .db文件。 所以我做了,然后在“本地化”选项卡下的“+”上通过XCode单击。 我现在有一个* .db文件在我的en.lproj和de.lproj文件夹。 我的问题:如果我想将数据库文件复制到应用程序的文档目录* .db文件当然不可用,因为它在* .lproj文件夹中。 有没有任何命令来获得正确的lproj文件夹? 澄清我的需求:这是行不通的 [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"mydatabase.db"] 这确实: [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"de.lproj/mydatabase.db"] …但我不想手动添加“de.lproj”和“en.lproj”等。 有没有办法dynamic修复它?

更新查询时,ios中的“数据库locking”错误

我正在使用下面的代码来更新使用sqlite 的查询 。 但是我得到"database is locked error" 。 我试图search一些SO链接,并build议closures数据库,但我又这样做了同样的错误。 我已经提到了在代码中出现错误的地方。 const char *dbpath = [databasePath UTF8String]; if (sqlite3_open(dbpath, &database) == SQLITE_OK) { NSString *locationNo =NULL; NSString *querySQL = [NSString stringWithFormat:@"select count(*) from code"]; const char *query_stmt = [querySQL UTF8String]; if (sqlite3_prepare_v2(database,query_stmt, -1, &statement, NULL) == SQLITE_OK) { if (sqlite3_step(statement) == SQLITE_ROW) { locationNo = [[NSString […]

SQLite“数据库磁盘映像格式不正确”

我遇到SQLite数据库被损坏的应用程序的问题。 以前有过这种奇怪的情况,但在iOS 7.1发布之后,它似乎已经变得更加普遍了。 我使用Matteo Bertozzi的SQLite包装,你可以在这里find: https : //github.com/ConnorD/simple-sqlite 数据库被破坏,并吐出错误database disk image is malformed ,一些查询可以运行,但现有的数据会搞砸。 我search了高和低,并找不到解决scheme,我希望有人在这里有一些想法,因为这是iOS更新后成为一个更常见的问题。 我试过这些修复命令: [sqlite executeNonQuery:@"pragma integrity_check"]; [sqlite executeNonQuery:@"reindex nodes"]; [sqlite executeNonQuery:@"reindex pristine"]; 产出是: SQLite Step Failed: database disk image is malformed SQLite Prepare Failed: unable to identify the object to be reindexed – Query: reindex nodes SQLite Prepare Failed: unable to identify […]

在iPhone ios中从sqlite数据库获取行数

背景 我一整天都在努力解决一个问题,我读了所有可以在互联网上find的文章和文档,但是我无法解决这个问题。 我正在为iPhone编写一个应用程序,我需要使用一个sqlite数据库( sqlite3 )。 主要问题 我已经创build了我的数据库,一切都很好,直到我想得到我的表中的行数。 表名是ARTICLES ,所以我写了 SELECT COUNT(*) FROM ARTICLES 我的程序什么也不做,并写入日志: 未知的错误。 const char *query = "SELECT COUNT (*) FROM ARTICLES"; sqlite3_stmt *compiledQuery; sqlite3_prepare_v2(database, query, -1, &compiledQuery, NULL); 程序在上面的代码中给出消息“ 未知的错误 ”,我不能得到行数。 谁可以帮我解决这个问题…或者可能与sqlite的东西是不正确的? 码 – (int) GetArticlesCount { if (sqlite3_open([self.dataBasePath UTF8String], &articlesDB) == SQLITE_OK) { const char* sqlStatement = "SELECT COUNT(*) FROM ARTICLES"; […]

在iOS下载并使用sqlite文件

当我将它存储在我的项目文件夹中时,我已经成功地使用了一个.sqlite文件。 我现在试图做同样的事情,除了从网上拉文件,而不是本地存储。 基于这个代码的任何build议? 我从代码的底部收到错误消息“与准备语句的问题”。 NSData *fetchedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://www.dropbox.com/s/zpcieluo2qv43vy/builds.sqlite?dl=1"]]; NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *filePath = [documentsPath stringByAppendingPathComponent:@"builds.sqlite"]; [fetchedData writeToFile:filePath atomically:YES]; NSFileManager *fileMgr = [NSFileManager defaultManager]; BOOL success = [fileMgr fileExistsAtPath:filePath]; if (!success) { NSLog(@"Cannot locate database file '%@'.", filePath); } if (!(sqlite3_open([filePath UTF8String], &db) == SQLITE_OK)) { NSLog(@"An error has […]

为什么我得到一个SQLITE_MISUSE:内存不足错误?

我正在写一个直接访问SQLite的iOS应用程序。 我在Android上多次做了这样的事情,所以我很努力地看到我的错误在哪里 – 但是我的插入正在返回SQLITE_MISUSE错误(代码21),消息“内存不足”。 以下是我已经采取的步骤来引导我这个插入。 首先, 创build表格 : NSString *sql = @"CREATE TABLE IF NOT EXISTS UsersTable (lastName TEXT,id TEXT PRIMARY KEY NOT NULL,picture BLOB,firstName TEXT,age TEXT,email TEXT,sex TEXT,height TEXT,weight TEXT)"; //create the database if it does not yet exist NSFileManager *filemgr = [NSFileManager defaultManager]; if ([filemgr fileExistsAtPath: path ] == NO) { const char […]

使用ngCordova $ cordovaSQLite插件与Ionic的错误

我目前正试图用我的应用程序实现ngCordova SQLite插件,但尚未产生一个工作的解决scheme。 我跟着Nic Raboy的博客文章 ,介绍如何用你的Ionic项目实现SQLite插件为“T”,但我仍然收到错误: 错误:undefined不是一个对象(评估'$ window.sqlitePlugin.openDatabase')当我尝试在iOS模拟器中运行应用程序时。 我也证实ngCordova和插件已经加载到我的项目中。 这是我的脚本如何加载到我的项目中的顺序: <script src="lib/ionic/js/ionic.bundle.js"></script> <script src="lib/ngCordova/dist/ng-cordova.js"></script> <script src="cordova.js"></script> <script src="js/app.js"></script> <script src="js/controllers.js"></script> 我的代码如下。 app.js angular.module('whoPaidLast', ['ionic', 'ngCordova', 'whoPaidLast.controllers', 'whoPaidLast.services']) .run(function($ionicPlatform, $cordovaSQLite) { $ionicPlatform.ready(function() { if(window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } if(window.StatusBar) { StatusBar.styleDefault(); } db = $cordovaSQLite.openDB({ name: 'accounts.db' }); $cordovaSQLite.execute(db, 'CREATE TABLE IF NOT EXISTS accounts (id […]

正确的方式插入数据到SQLite数据库iPhone

如何在sqlite iPhone中插入数据到表中? 我正在尝试追踪,但是失败了: NSString *query=[NSString stringWithFormat:@"insert into %@ (name) values ('%@')", table name,myName ]; sqlite3 *database; sqlite3_stmt *createStmt = nil; if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { if (createStmt == nil) { if (sqlite3_prepare_v2(database, [query UTF8String], -1, &createStmt, NULL) != SQLITE_OK) { return NO; } sqlite3_exec(database, [query UTF8String], NULL, NULL, NULL); return YES; } return […]

iOS数据库教程

我是新来的iOS,并试图学习如何远程设置数据库,并使我的项目连接到它。 我一直在网上search教程,但不能真的find任何好的。 所以我想知道如果有人可以推荐我一些很好的教程,学习如何将我的iOS项目连接到数据库。 任何帮助是极大的赞赏。 谢谢!