• 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;
    }
  • 相关阅读:
    [转载].net 访问oracle的总结
    .net平台新语言——Boo 试用
    抛弃ConfigurationManager , 实现面向对象读写配置文件
    延长或控制Session的有效期的方法总结
    jQuery Validation:让验证变得如此容易
    单进程资源共享
    .net快速创建PDF文档 by c#
    百度之星程序设计大赛初赛题4低频词过滤
    Google Talk
    百度之星,我的比赛结束了:)
  • 原文地址:https://www.cnblogs.com/gcb999/p/3200308.html
Copyright © 2020-2023  润新知