Changes between Version 8 and Version 9 of Docs/Prog/Manual/ApplicationLibraries/lib825mssql
- Timestamp:
- 10/27/26 13:24:03 (4 days ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Docs/Prog/Manual/ApplicationLibraries/lib825mssql
v8 v9 32 32 This 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. 33 33 34 A 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 34 36 {{{#!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 }37 if(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 } 40 42 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-increments47 }48 sql +=49 "cost TEXT," // amount of this transaction50 "pmt_type TEXT," // CASH if cash, else CREDIT if Account customer51 "badge TEXT," // Badge ID (if CREDIT)52 "customer TEXT,"; // The customer name (if CREDIT)43 if(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 } 50 sql += 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) 53 55 54 for(n = 0; n < MAX_DB_AXLES; n++) { 55 sql += "axle" + to_string(n + 1) + " REAL,"; 56 } 56 for(n = 0; n < MAX_DB_AXLES; n++) { 57 sql += "axle" + to_string(n + 1) + " REAL,"; 58 } 59 sql += "grossT REAL" // Total wt (sum of wts) 60 ",datetm DATETIME" 61 ");"; 62 if(dynamic_cast<CDBMSSQL*>(appDB)) { 63 sql += " END"; 64 } 57 65 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 66 if(appDB->Execute(sql) == false) { 67 DrawErrorBox("Error creating transaction table", 2); 68 } 69 69 }}}
![(please configure the [header_logo] section in trac.ini)](/chrome/site/cardinal.gif)