Changeset 443
- Timestamp:
- 08/26/09 18:49:00 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp
r442 r443 157 157 158 158 miss = new Mission[10]; 159 for(size_t i = 0; i < 10; i++) 159 for(size_t i = 0; i < 10; i++) { 160 160 miss[i].services = new Service[30]; 161 } 161 162 162 163 Current_ID = 0; … … 177 178 ServiceManagementLayer::CreateServicesDB() 178 179 { 179 sqlite3_stmt *ppStmt; /* OUT: Statement handle */180 sqlite3_stmt *ppStmt; /* OUT: Statement handle */ 180 181 const char *pzTail; /* OUT: Pointer to unused portion of zSql */ 181 182 //_services_DB = (services_DB) malloc(sizeof(struct services_s)); 182 int32_t rc; /* sqlite command return code */ 183 183 184 _services_DB = new services_s; 184 // copy filename185 185 _services_DB->filename="Services_Table"; 186 // execute create database command187 // database handle188 //_services_DB->db = NULL;189 186 sqlite3_open(_services_DB->filename.c_str(), &(_services_DB->db)); 187 190 188 char* cols[] = {(char *)"ID_Num", (char *)"Service_Name"}; 191 189 192 193 // copy tablename194 190 _services_DB->tablename="Services"; 195 191 196 //If program execution ends in anything other than a ordered shutdown, DB's will still be there for next run 197 //Need to get rid of it so that old data isn't inadvertantly used in the next execution cycle 192 /* If program execution ends in anything other than a ordered shutdown, DB's will still 193 * be there for next run. Need to get rid of it so that old data isn't inadvertantly 194 * used in the next execution cycle. */ 198 195 _services_DB->command = "DROP TABLE IF EXISTS Services;"; 199 196 200 int rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail); 201 if( rc!=SQLITE_OK && rc!=101 ) 202 printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc); 197 rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail); 198 if((rc != SQLITE_OK) && (rc != 101)) 199 WARNING("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc); 200 203 201 rc = sqlite3_step(ppStmt); 204 if( rc!=SQLITE_OK && rc!=101 ) 205 printf("ServiceManagementLayer::CreateServicesDB 'step' error\n"); 206 207 // number of columns in the table 202 if((rc != SQLITE_OK) && (rc != 101)) 203 WARNING("ServiceManagementLayer::CreateServicesDB 'step' error\n"); 204 208 205 _services_DB->num_columns = 2; 209 206 210 / / generate command207 /* Generate command */ 211 208 _services_DB->command="CREATE TABLE "; 212 209 _services_DB->command.append(_services_DB->tablename); … … 217 214 _services_DB->command.append(" TEXT);"); 218 215 219 // execute create table command 220 216 /* Execute create table command */ 221 217 rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail); 222 if( rc!=SQLITE_OK && rc!=101 ) 223 printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc); 218 if((rc != SQLITE_OK) && (rc != 101)) 219 WARNING("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc); 220 224 221 rc = sqlite3_step(ppStmt); 225 if( rc!=SQLITE_OK && rc!=101)226 printf("ServiceManagementLayer::CreateServicesDB 'step' error\n");222 if((rc != SQLITE_OK) && (rc != 101)) 223 WARNING("ServiceManagementLayer::CreateServicesDB 'step' error\n"); 227 224 } 228 225 … … 236 233 ServiceManagementLayer::CreateDataDB() 237 234 { 238 sqlite3_stmt *ppStmt; /* OUT: Statement handle */235 sqlite3_stmt *ppStmt; /* OUT: Statement handle */ 239 236 const char *pzTail; /* OUT: Pointer to unused portion of zSql */ 240 241 _data_DB = new data_s;//(data_DB) malloc(sizeof(struct data_s)); 242 243 // create database 244 245 // copy filename 237 int32_t rc; /* sqlite command return code */ 238 239 _data_DB = new data_s; 240 246 241 _data_DB->filename="Data_Table"; 247 // execute create database command248 // database handle249 //_services_DB->db = NULL;250 242 sqlite3_open(_data_DB->filename.c_str(), &(_data_DB->db)); 243 251 244 char* cols[] = {(char *)"Tag", (char *)"Data"}; 252 245 253 // create table254 255 // copy tablename256 246 _data_DB->tablename="Data"; 257 247 _data_DB->command="DROP TABLE IF EXISTS Data;"; 258 248 259 int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail); 260 if( rc!=SQLITE_OK && rc!=101 ) 261 printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc); 249 rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail); 250 if((rc != SQLITE_OK) && (rc != 101)) 251 WARNING("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc); 252 262 253 rc = sqlite3_step(ppStmt); 263 if( rc!=SQLITE_OK && rc!=101 ) 264 printf("ServiceManagementLayer::CreateServicesDB 'step' error\n"); 265 266 267 // number of columns in the table 254 if((rc != SQLITE_OK) && (rc != 101)) 255 WARNING("ServiceManagementLayer::CreateDataDB 'step' error\n"); 256 268 257 _data_DB->num_columns = 2; 269 258 270 / / generate command259 /* Generate command */ 271 260 _data_DB->command="CREATE TABLE "; 272 261 _data_DB->command.append(_data_DB->tablename); 273 262 _data_DB->command.append("("); 274 263 _data_DB->command.append(cols[0]); 275 //First column is the name of the data (coresponding to the name of the output/input pair) 276 //It is the primary key so any subsequent data with the same name will replace the row 264 265 /* First column is the name of the data (corresponding to the name of the output/input pair) 266 * It is the primary key so any subsequent data with the same name will replace the row. */ 277 267 _data_DB->command.append(" TEXT PRIMARY KEY ON CONFLICT REPLACE, "); 278 268 _data_DB->command.append(cols[1]); 279 269 _data_DB->command.append(" TEXT);"); 280 270 281 // execute create table command282 283 271 rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail); 284 if( rc!=SQLITE_OK && rc!=101 ) 285 printf("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc); 272 if((rc != SQLITE_OK) && (rc != 101)) 273 WARNING("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc); 274 286 275 rc = sqlite3_step(ppStmt); 287 if( rc!=SQLITE_OK && rc!=101)288 printf("ServiceManagementLayer::CreateDataDB 'step' error\n");276 if((rc != SQLITE_OK) && (rc != 101)) 277 WARNING("ServiceManagementLayer::CreateDataDB 'step' error\n"); 289 278 } 290 279