Changes between Version 44 and Version 45 of Docs/Prog/Manual/ApplicationLibraries/lib825db


Ignore:
Timestamp:
01/20/26 11:02:17 (2 weeks ago)
Author:
Don Wilson
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Docs/Prog/Manual/ApplicationLibraries/lib825db

    v44 v45  
    142142The following example shows creating a table with PRIMARY KEY AUTO_INCREMENT the keyword is AUTO_INCREMENT in MySQL and AUTOINCREMENT in SQLite.
    143143{{{#!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                 ");";
     144string sql;
     145sql = "CREATE TABLE IF NOT EXISTS trans (";
     146if(dynamic_cast<CDBMySQL*>(appDB)) {
     147  sql += "id INTEGER PRIMARY KEY AUTO_INCREMENT,";
     148} else {
     149  sql += "id INTEGER PRIMARY KEY AUTOINCREMENT,";
     150}
     151sql +=  "datetm DATETIME, "
     152        "cost VARCHAR(16),"
     153        "pmt_type VARCHAR(50),"
     154        "badge VARCHAR(20),"
     155        "customer VARCHAR(20),"
     156        "truck VARCHAR(20),"
     157        "mileage INT,"
     158        "gross REAL,"
     159        "gross2 REAL,"
     160        "gross3 REAL,"
     161        "gross4 REAL,"
     162        "grossT REAL,"
     163        "axles INT,"
     164        "code TEXT,"
     165        "codeexpires INT"
     166");";
    169167
    170         // if (!rc_is_okay(db.execute(zTrans)))
    171         if(appDB->Execute(/*zTrans*/ sql) == false) {
    172                 DrawErrorBox("Error creating transaction table", 2);
    173         }
    174 
     168if(appDB->Execute(sql) == false) {
     169  DrawErrorBox("Error creating transaction table", 2);
     170}
    175171}}}
    176172