Skip to content

Working with Tables

ziminji edited this page Oct 23, 2011 · 12 revisions

Working with Tables

Example #1 (Create Table)

CREATE TABLE Customer (pk INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(35));
// Creates the SQL statement
ZIMSqlCreateTableStatement *create = [[ZIMSqlCreateTableStatement alloc] init];
[create table: @"Customer"];
[create column: @"pk" type: ZIMSqlDataTypeInteger defaultValue: ZIMSqlDefaultValueIsAutoIncremented];
[create column: @"name" type: ZIMSqlDataTypeVarChar(35)];
NSString *statement = [create statement];
NSLog(@"%@", statement);

// Executes the SQL statement
NSNumber *result = [ZIMDbConnection dataSource: @"live" execute: statement];

Example #2 (Drop Table)

DROP TABLE Customer;
// Creates the SQL statement
ZIMSqlDropTableStatement *drop = [[ZIMSqlDropTableStatement alloc] init];
[drop table: @"Customer"];
NSString *statement = [drop statement];
NSLog(@"%@", statement);

// Executes the SQL statement
NSNumber *result = [ZIMDbConnection dataSource: @"live" execute: statement];
Clone this wiki locally