zoukankan      html  css  js  c++  java
  • ios中Pldatabase的用法(2)

    @implementation AppGlobal
    
    
    static NSString* strHostName;
    static NSString* strVersion;
    static PLSqliteDatabase* dbHelper;
    static CConfigSetting* configSetting;
    
    
    + (BOOL) Init
    {
    
        strHostName = HTTPURLPREFIX;
    
        strVersion = @"1.01";
        
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *dbPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"TaxOffice.db"];
        dbHelper = [[PLSqliteDatabase alloc] initWithPath:dbPath];  
        
        NSLog(@"TaxOffice.db  path = %@",dbPath);
        if (![DBInit initDB])
            return FALSE;
        
        configSetting = [[CConfigSetting alloc] init];
        return TRUE;
    }
    
    + (void) DeInit
    {
        [dbHelper close];
        [dbHelper release];
        [configSetting release];
    }
    
    
    + (NSString*) DefaultHost
    {
        return strHostName;
    }
    
    + (NSString*) Version
    {
        return strVersion;
    }
    
    + (PLSqliteDatabase*) DbHelper
    {
        return dbHelper;
    }
    
    + (CConfigSetting*) ConfigSetting
    {
        return configSetting;
    }
    
    @end
    +(BOOL) initDB
    {
        PLSqliteDatabase* idb = [AppGlobal DbHelper];
        
        if (![idb open]) {
            return FALSE;
        }
    
        // 配置信息表    
        if (![idb tableExists:@"Config"]) {
            if (![idb executeUpdate: @"CREATE TABLE Config(key integer,value text)"])  
                return FALSE;
        }
    
        // 客户信息表
        if (![idb tableExists:@"Customers"]) {
            NSString *strSql = @"CREATE TABLE Customers(id integer PRIMARY KEY autoincrement not null,"
                                "idno text, name text, tel text, remark text)";
            if (![idb executeUpdate: strSql]) {
                return FALSE;
            }
        }
        
        // 商品信息表
        if (![idb tableExists:@"Products"]) {
            NSString *strSql = @"CREATE TABLE Products(id integer PRIMARY KEY autoincrement not null,"
                                "idno text, name text, type integer, price real,"
                                "amount real, units text, remark text)";
            if (![idb executeUpdate: strSql]) {
                return FALSE;
            }
        }
        
        //
        
        return TRUE;
    }
  • 相关阅读:
    flume 安装过程记录
    hive 动态分区插入
    hive 数据导入
    scala 学习笔记
    hive 日志
    Linux下设置和查看环境变量
    数据结构(4):图解递归调用机制
    使用数据结构栈实现表达式计算器
    数据结构(3):java使用数组模拟堆栈
    使用Vue和Element-ui的cdn模式临摹一个后台框架
  • 原文地址:https://www.cnblogs.com/gcb999/p/3200308.html
Copyright © 2011-2022 走看看