iphone开发 SQLite数据库使用
我现在要使用SQLite3.0创建一个数据库,然后在数据库中创建一个表格。
首先要引入SQLite3.0的lib库。然后包含头文件#import <sqlite3.h>
【1】打开数据库,如果没有,那么创建一个
sqlite3* database_;
-(BOOL) open{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"mydb.sql"];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL find = [fileManager fileExistsAtPath:path];
//找到数据库文件mydb.sql
if (find) {
NSLog(@"Database file have already existed.");
if(sqlite3_open([path UTF8String], &database_) != SQLITE_OK) {
sqlite3_close(database_);
NSLog(@"Error: open database file.");
return NO;
}
return YES;
}
if(sqlite3_open([path UTF8String], &database_) == SQLITE_OK) {
bFirstCreate_ = YES;
[self createChannelsTable
:database_];//在后面实现函数createChannelsTable
return YES;
} else {
sqlite3_close(database_);
NSLog(@"Error: open database file.");
return NO;
}
 
相关文档:
/*=================================
.* The Standard include file.
.*
.*===============================*/
#include <stdio.h>
#include <stdlib.h>
/*=================================
.*
.* The extend include file.
.*
.*===============================*/
#include "sqlit ......
背景
当前移动设备开发领域,在本地数据存储方面,Sqlite几乎成了事实标准,Andriod (android.database.sqlite),iPhone (SQLite for iPhone SDK 和 FMDB for iPhone),Palm WebOS (webOS SQL Tutorial),新版本的Symbian也直接built-in Sqlite了(20 million Symbian smartphones shipped in Q3 2007 Newer versions of th ......
先记下来:
FileOutputStream outputStream = openFileOutput("mydb", 0);
InputStream inputStream = response.getEntity().getContent();
byte[] data = new byte[bufferSize];
for (int i = inputStream.read(data); i > 0; i = inputStream
.read(data)) {
& ......
1:从sqlite的官网上下载源码 http://www.sqlite.org/download.html
2:打开vs2008工程新建一个空的dll工程。
3:把sqlite3.h,sqlite3.cpp,sqlite3.def分别加入到head file 和source file下。
4:编译程序。 这时只能得到sqlite3.dll文件。
5:打开vs2008自带的命令行: 切到sqlite3.def所在的目录。
6:运行 ......
SQLite官方网站例子:
#include <stdio.h>
#include <sqlite3.h>
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
i ......