| | 141 | |
| | 142 | The following example shows creating a table with PRIMARY KEY AUTO_INCREMENT the keyword is AUTO_INCREMENT in MySQL and AUTOINCREMENT in SQLite. |
| | 143 | {{{#!c++ |
| | 144 | string sql; |
| | 145 | sql = "CREATE TABLE IF NOT EXISTS trans ("; |
| | 146 | if(dynamic_cast<CDBMySQL*>(appDB)) { |
| | 147 | sql += "id INTEGER PRIMARY KEY AUTO_INCREMENT,"; |
| | 148 | } else { |
| | 149 | sql += "id INTEGER PRIMARY KEY AUTOINCREMENT,"; |
| | 150 | } |
| | 151 | //sql += "trans_time VARCHAR(16)," // Time in |
| | 152 | // "trans_date VARCHAR(16)," // Date in |
| | 153 | sql += "datetm DATETIME, " |
| | 154 | "cost VARCHAR(16)," // amount of this transaction |
| | 155 | "pmt_type VARCHAR(50)," // "ID Card", "Credit Card", "Code/Reweigh" |
| | 156 | "badge VARCHAR(20)," // Badge ID (if CREDIT) |
| | 157 | "customer VARCHAR(20)," // The customer name (if CREDIT) |
| | 158 | "truck VARCHAR(20)," // Company Truck ID if provided |
| | 159 | "mileage INT," |
| | 160 | "gross REAL," |
| | 161 | "gross2 REAL," |
| | 162 | "gross3 REAL," |
| | 163 | "gross4 REAL," |
| | 164 | "grossT REAL," // Total wt (sum of wts) |
| | 165 | "axles INT," |
| | 166 | "code TEXT," |
| | 167 | "codeexpires INT" |
| | 168 | ");"; |
| | 169 | |
| | 170 | // if (!rc_is_okay(db.execute(zTrans))) |
| | 171 | if(appDB->Execute(/*zTrans*/ sql) == false) { |
| | 172 | DrawErrorBox("Error creating transaction table", 2); |
| | 173 | } |
| | 174 | |
| | 175 | }}} |
| | 176 | |