| | 9 | |
| | 10 | An example to have an app support SQLite, MySQL, or SQL Server: |
| | 11 | {{{#!c++ |
| | 12 | CAppDatabaseCfg appDBcfg; |
| | 13 | string path = appDataPath + CFGFILE_DB; |
| | 14 | appDBcfg.SetArchiveFilepath(path); |
| | 15 | appDBcfg.ReadConfig(); |
| | 16 | |
| | 17 | if(appDBcfg.GetDBType() == CAppDatabaseCfg::appDataMySQL) { |
| | 18 | appDB = new CDBMySQL(appDBcfg.GetServer(), appDBcfg.GetUser(), appDBcfg.GetPassword(), appDBcfg.GetDatabase()); |
| | 19 | } else if(appDBcfg.GetDBType() == CAppDatabaseCfg::appDataMSSQL) { |
| | 20 | appDB = new CDBMSSQL(appDBcfg.GetServer(), appDBcfg.GetUser(), appDBcfg.GetPassword(), appDBcfg.GetDatabase()); |
| | 21 | } else { |
| | 22 | appDB = new CDBSQLite("/mnt/nand/apps/<appdir>/myapp.db3"); |
| | 23 | } |
| | 24 | |
| | 25 | if(appDB->OpenDatabase() == false) { |
| | 26 | DEBUG_MSG("Error [%s]\n", appDB->GetErrorMsg().c_str()); |
| | 27 | DrawErrorBox("Cannot open database", 4); |
| | 28 | } |
| | 29 | }}} |
| | 30 | CAppDatabaseCfg is not part of lib825db. This code is in the ID Storage app to provide a user interface and load/save database configuration. The files appdatabase.cpp and appdatabase.h may be copied from ID Storage for your own apps and customized if desired. |
| | 31 | |
| | 32 | This instantiates a CDBMySQL object for MySQL, or 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 | |