Changes between Version 8 and Version 9 of Docs/Prog/Manual/ApplicationLibraries/lib825mssql


Ignore:
Timestamp:
10/27/26 13:24:03 (4 days ago)
Author:
Don Wilson
Comment:

--

Legend:

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

    v8 v9  
    3232This instantiates a CDBMySQL object for MySQL, a CDBMSSQL object for SQL Server, or a CDBSQLite object for SQLite based on the configuration. The created object is assigned to the pointer CDB* appDB.
    3333
     34A common SQL statement for 825 projects is "CREATE TABLE IF NOT EXISTS" for startup code. Microsoft SQL Server does not support this. The "IF OBJECT_ID('tblname', 'U') IS NULL BEGIN CREATE TABLE" may be used instead. The "INTEGER PRIMARY KEY AUTO_INCREMENT" also will need to be handled differently.
     35
    3436{{{#!c++
    35         if(dynamic_cast<CDBMSSQL*>(appDB)) {
    36                 sql = "IF OBJECT_ID('dbo.axleTrans', 'U') IS NULL BEGIN CREATE TABLE axleTrans (";
    37         } else {
    38                 sql = "CREATE TABLE IF NOT EXISTS axleTrans (";
    39         }
     37if(dynamic_cast<CDBMSSQL*>(appDB)) {
     38  sql = "IF OBJECT_ID('dbo.axleTrans', 'U') IS NULL BEGIN CREATE TABLE axleTrans (";
     39} else {
     40  sql = "CREATE TABLE IF NOT EXISTS axleTrans (";
     41}
    4042
    41                         if(dynamic_cast<CDBMySQL*>(appDB)) {
    42                                 sql +=  "id INTEGER PRIMARY KEY AUTO_INCREMENT,";
    43                         } else if(dynamic_cast<CDBMSSQL*>(appDB)) {
    44                                 sql += "id INTEGER IDENTITY(1,1) PRIMARY KEY,";
    45                         } else {
    46                                 sql += "id INTEGER PRIMARY KEY,"; // SQLite: INTEGER PRIMARY KEY aliases ROWID and auto-increments
    47                         }
    48                         sql +=
    49                                 "cost TEXT," // amount of this transaction
    50                                 "pmt_type TEXT," // CASH if cash, else CREDIT if Account customer
    51                                 "badge TEXT," // Badge ID (if CREDIT)
    52                                 "customer TEXT,"; // The customer name (if CREDIT)
     43if(dynamic_cast<CDBMySQL*>(appDB)) {
     44  sql +=        "id INTEGER PRIMARY KEY AUTO_INCREMENT,";
     45} else if(dynamic_cast<CDBMSSQL*>(appDB)) {
     46  sql += "id INTEGER IDENTITY(1,1) PRIMARY KEY,";
     47} else {
     48  sql += "id INTEGER PRIMARY KEY,"; // SQLite: INTEGER PRIMARY KEY aliases ROWID and auto-increments
     49}
     50sql +=
     51"cost TEXT," // amount of this transaction
     52"pmt_type TEXT," // CASH if cash, else CREDIT if Account customer
     53"badge TEXT," // Badge ID (if CREDIT)
     54"customer TEXT,"; // The customer name (if CREDIT)
    5355
    54                         for(n = 0; n < MAX_DB_AXLES; n++) {
    55                                 sql += "axle" + to_string(n + 1) + " REAL,";
    56                         }
     56for(n = 0; n < MAX_DB_AXLES; n++) {
     57  sql += "axle" + to_string(n + 1) + " REAL,";
     58}
     59sql += "grossT REAL" // Total wt (sum of wts)
     60",datetm DATETIME"
     61");";
     62if(dynamic_cast<CDBMSSQL*>(appDB)) {
     63  sql += " END";
     64}
    5765
    58                         sql += "grossT REAL" // Total wt (sum of wts)
    59                                 ",datetm DATETIME"
    60                                 ");";
    61         if(dynamic_cast<CDBMSSQL*>(appDB)) {
    62                 sql += " END";
    63         }
    64 
    65                 if(appDB->Execute(sql) == false) {
    66                         DrawErrorBox("Error creating transaction table", 2);
    67                 }
    68 
     66if(appDB->Execute(sql) == false) {
     67  DrawErrorBox("Error creating transaction table", 2);
     68}
    6969}}}