- Timestamp:
- 2010-05-06T12:49:54+12:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/common-src/src/lib/mssqldbclass.cpp
r17476 r22043 143 143 void mssqldbclass::deletekey (const text_t &key) 144 144 { 145 text_t sql_cmd = "DELETE FROM data_" + tableid + " WHERE one_key=N'" + mssql_safe(key) + "'";146 dbquery(sql_cmd);145 text_t sql_cmd = "DELETE FROM data_" + tableid + " WHERE one_key=N'" + sql_safe(key) + "'"; 146 sqlexec(sql_cmd); 147 147 } 148 148 … … 151 151 bool mssqldbclass::getkeydata (const text_t& key, text_t &data) 152 152 { 153 text_t sql_cmd = "SELECT one_value FROM data_" + tableid + " WHERE one_key=N'" + mssql_safe(key) + "'";153 text_t sql_cmd = "SELECT one_value FROM data_" + tableid + " WHERE one_key=N'" + sql_safe(key) + "'"; 154 154 vector<text_tmap> sql_results; 155 155 if (!sqlgetarray(sql_cmd, sql_results) || sql_results.size() == 0) … … 196 196 if (!exists(key)) 197 197 { 198 text_t sql_cmd = "INSERT INTO data_" + tableid + " (one_key, one_value) VALUES (N'" + mssql_safe(key) + "', N'" + mssql_safe(data) + "')";199 return dbquery(sql_cmd);198 text_t sql_cmd = "INSERT INTO data_" + tableid + " (one_key, one_value) VALUES (N'" + sql_safe(key) + "', N'" + sql_safe(data) + "')"; 199 return sqlexec(sql_cmd); 200 200 } 201 201 else 202 202 { 203 text_t sql_cmd = "UPDATE data_" + tableid + " SET one_value='" + mssql_safe(data) + "' WHERE one_key=N'" + mssql_safe(key) + "'";204 return dbquery(sql_cmd);203 text_t sql_cmd = "UPDATE data_" + tableid + " SET one_value='" + sql_safe(data) + "' WHERE one_key=N'" + sql_safe(key) + "'"; 204 return sqlexec(sql_cmd); 205 205 } 206 206 } … … 221 221 222 222 // Get the entries in the "document_metadata" table where the element and value matches those specified 223 text_t sql_cmd = "SELECT DISTINCT docOID FROM document_metadata_" + tableid + " WHERE element IN (N'" + mssql_safe(metadata_element_names[0]) + "'";223 text_t sql_cmd = "SELECT DISTINCT docOID FROM document_metadata_" + tableid + " WHERE element IN (N'" + sql_safe(metadata_element_names[0]) + "'"; 224 224 for (int i = 1; i < metadata_element_names.size(); i++) 225 225 { 226 sql_cmd += ",'" + mssql_safe(metadata_element_names[i]) + "'";227 } 228 sql_cmd += ") AND value='" + mssql_safe(metadata_value) + "'";226 sql_cmd += ",'" + sql_safe(metadata_element_names[i]) + "'"; 227 } 228 sql_cmd += ") AND value='" + sql_safe(metadata_value) + "'"; 229 229 230 230 // If we're sorting the documents by a certain metadata element, extend the SQL command to do this 231 231 if (sort_by_metadata_element_name != "") 232 232 { 233 sql_cmd = "SELECT docOID FROM (" + sql_cmd + ") LEFT JOIN (SELECT docOID,value from document_metadata_" + tableid + " WHERE element=N'" + mssql_safe(sort_by_metadata_element_name) + "') USING (docOID) ORDER by value";233 sql_cmd = "SELECT docOID FROM (" + sql_cmd + ") LEFT JOIN (SELECT docOID,value from document_metadata_" + tableid + " WHERE element=N'" + sql_safe(sort_by_metadata_element_name) + "') USING (docOID) ORDER by value"; 234 234 } 235 235 … … 275 275 276 276 // Get the entries in the "document_metadata" table where the element matches that specified 277 text_t sql_cmd = "SELECT DISTINCT docOID," + value_select_expression + " FROM document_metadata_" + tableid + " WHERE element IN (N'" + mssql_safe(metadata_element_names[0]) + "'";277 text_t sql_cmd = "SELECT DISTINCT docOID," + value_select_expression + " FROM document_metadata_" + tableid + " WHERE element IN (N'" + sql_safe(metadata_element_names[0]) + "'"; 278 278 for (int i = 1; i < metadata_element_names.size(); i++) 279 279 { 280 sql_cmd += ",N'" + mssql_safe(metadata_element_names[i]) + "'";280 sql_cmd += ",N'" + sql_safe(metadata_element_names[i]) + "'"; 281 281 } 282 282 sql_cmd += ")"; … … 285 285 if (metadata_value_filter != "") 286 286 { 287 sql_cmd += " AND value GLOB N'" + mssql_safe(metadata_value_filter) + "'";287 sql_cmd += " AND value GLOB N'" + sql_safe(metadata_value_filter) + "'"; 288 288 } 289 289 … … 308 308 309 309 310 //-------------------------------------------------------------------------------------// 311 // MS-SQL Private Utilities [START] 312 //-------------------------------------------------------------------------------------// 313 314 // dbquery(const text_t &sql) 310 // sqlexec(const text_t &sql) 315 311 // Takes a sql statement and executes it 316 312 // Returns false if failed, otherwise true 317 bool mssqldbclass:: dbquery(const text_t &sql)313 bool mssqldbclass::sqlexec (const text_t &sql) 318 314 { 319 315 char *sql_c = sql.getcstr(); … … 324 320 if (FAILED(cmd.CreateInstance(__uuidof(Command)))) 325 321 { 326 cerr << "mssqldbclass:: dbquery: CreateInstance failed" << endl;322 cerr << "mssqldbclass::sqlexec: CreateInstance failed" << endl; 327 323 return false; 328 324 } … … 339 335 text_t error; 340 336 error.setcstr(e.ErrorMessage()); 341 cerr << "mssqldbclass:: dbquery: _com_error: (" << sql << ") : (" << error << ")" << endl;337 cerr << "mssqldbclass::sqlexec: _com_error: (" << sql << ") : (" << error << ")" << endl; 342 338 rv = false; 343 339 } 344 340 catch (...) 345 341 { 346 cerr << "mssqldbclass:: dbquery: unknown error: (" + sql + ")" << endl;342 cerr << "mssqldbclass::sqlexec: unknown error: (" + sql + ")" << endl; 347 343 rv = false; 348 344 } … … 426 422 427 423 428 text_t mssqldbclass::mssql_safe (const text_t &value_arg) 424 // returns true if exists 425 bool sqlitedbclass::sqltableexists(const text_t &table_name) 426 { 427 cerr << "**** mssqldbclass::sqltableexists: This implementation is untested!" << endl; 428 cerr << "**** Remove warning message once confirmed/fixed to works as required" << endl; 429 430 text_t sql_cmd = "SELECT name FROM sysobjects WHERE name='" + sql_safe(table_name) 431 + "' AND OBJECTPROPERTY(id,'IsUserTable')=1"; 432 433 vector<text_tmap> sql_results; 434 if (!sqlgetarray(sql_cmd, sql_results) || sql_results.size() == 0) 435 { 436 return false; 437 } 438 439 return true; 440 } 441 442 443 text_t mssqldbclass::sql_safe (const text_t &value_arg) 429 444 { 430 445 text_t value = value_arg; … … 434 449 435 450 451 //---------------------------------------------------------------------------// 452 // MS-SQL Private Utilities [START] 453 //---------------------------------------------------------------------------// 454 455 436 456 // read_infodb_file(text_t filename) 437 // Unlike the others (sqlite and gdbm), this is a server-client based database. 438 // Therefore, instead of store the actual database, we store the infoserver-client based database. 457 // Unlike the others (sqlite and gdbm), this is a server-client based 458 // database. Therefore, instead of store the actual database, we store the 459 // infoserver-client based database. 439 460 // What we want to do here is to have the 440 461 text_tmap mssqldbclass::read_infodb_file(text_t filename) … … 494 515 } 495 516 496 //--------------------------------------------------------------------------- ----------//517 //---------------------------------------------------------------------------// 497 518 // MS-SQL Private Utilities [END] 498 //--------------------------------------------------------------------------- ----------//499 519 //---------------------------------------------------------------------------// 520
Note:
See TracChangeset
for help on using the changeset viewer.