diff options
Diffstat (limited to 'src/dutil/sqlutil.cpp')
| -rw-r--r-- | src/dutil/sqlutil.cpp | 119 |
1 files changed, 67 insertions, 52 deletions
diff --git a/src/dutil/sqlutil.cpp b/src/dutil/sqlutil.cpp index 099c6ae9..63ee80ac 100644 --- a/src/dutil/sqlutil.cpp +++ b/src/dutil/sqlutil.cpp | |||
| @@ -9,6 +9,21 @@ | |||
| 9 | #define DBINITCONSTANTS | 9 | #define DBINITCONSTANTS |
| 10 | #include "sqlutil.h" | 10 | #include "sqlutil.h" |
| 11 | 11 | ||
| 12 | |||
| 13 | // Exit macros | ||
| 14 | #define SqlExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
| 15 | #define SqlExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
| 16 | #define SqlExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
| 17 | #define SqlExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
| 18 | #define SqlExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
| 19 | #define SqlExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
| 20 | #define SqlExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SQLUTIL, p, x, e, s, __VA_ARGS__) | ||
| 21 | #define SqlExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SQLUTIL, p, x, s, __VA_ARGS__) | ||
| 22 | #define SqlExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SQLUTIL, p, x, e, s, __VA_ARGS__) | ||
| 23 | #define SqlExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SQLUTIL, p, x, s, __VA_ARGS__) | ||
| 24 | #define SqlExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SQLUTIL, e, x, s, __VA_ARGS__) | ||
| 25 | #define SqlExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SQLUTIL, g, x, s, __VA_ARGS__) | ||
| 26 | |||
| 12 | // private prototypes | 27 | // private prototypes |
| 13 | static HRESULT FileSpecToString( | 28 | static HRESULT FileSpecToString( |
| 14 | __in const SQL_FILESPEC* psf, | 29 | __in const SQL_FILESPEC* psf, |
| @@ -54,7 +69,7 @@ extern "C" HRESULT DAPI SqlConnectDatabase( | |||
| 54 | //obtain access to the SQLOLEDB provider | 69 | //obtain access to the SQLOLEDB provider |
| 55 | hr = ::CoCreateInstance(CLSID_SQLOLEDB, NULL, CLSCTX_INPROC_SERVER, | 70 | hr = ::CoCreateInstance(CLSID_SQLOLEDB, NULL, CLSCTX_INPROC_SERVER, |
| 56 | IID_IDBInitialize, (LPVOID*)&pidbInitialize); | 71 | IID_IDBInitialize, (LPVOID*)&pidbInitialize); |
| 57 | ExitOnFailure(hr, "failed to create IID_IDBInitialize object"); | 72 | SqlExitOnFailure(hr, "failed to create IID_IDBInitialize object"); |
| 58 | 73 | ||
| 59 | // if there is an instance | 74 | // if there is an instance |
| 60 | if (wzInstance && *wzInstance) | 75 | if (wzInstance && *wzInstance) |
| @@ -65,7 +80,7 @@ extern "C" HRESULT DAPI SqlConnectDatabase( | |||
| 65 | { | 80 | { |
| 66 | hr = StrAllocString(&pwzServerInstance, wzServer, 0); | 81 | hr = StrAllocString(&pwzServerInstance, wzServer, 0); |
| 67 | } | 82 | } |
| 68 | ExitOnFailure(hr, "failed to allocate memory for the server instance"); | 83 | SqlExitOnFailure(hr, "failed to allocate memory for the server instance"); |
| 69 | 84 | ||
| 70 | // server[\instance] | 85 | // server[\instance] |
| 71 | rgdbpInit[cProperties].dwPropertyID = DBPROP_INIT_DATASOURCE; | 86 | rgdbpInit[cProperties].dwPropertyID = DBPROP_INIT_DATASOURCE; |
| @@ -124,13 +139,13 @@ extern "C" HRESULT DAPI SqlConnectDatabase( | |||
| 124 | 139 | ||
| 125 | // create and set the property set | 140 | // create and set the property set |
| 126 | hr = pidbInitialize->QueryInterface(IID_IDBProperties, (LPVOID*)&pidbProperties); | 141 | hr = pidbInitialize->QueryInterface(IID_IDBProperties, (LPVOID*)&pidbProperties); |
| 127 | ExitOnFailure(hr, "failed to get IID_IDBProperties object"); | 142 | SqlExitOnFailure(hr, "failed to get IID_IDBProperties object"); |
| 128 | hr = pidbProperties->SetProperties(1, rgdbpsetInit); | 143 | hr = pidbProperties->SetProperties(1, rgdbpsetInit); |
| 129 | ExitOnFailure(hr, "failed to set properties"); | 144 | SqlExitOnFailure(hr, "failed to set properties"); |
| 130 | 145 | ||
| 131 | //initialize connection to datasource | 146 | //initialize connection to datasource |
| 132 | hr = pidbInitialize->Initialize(); | 147 | hr = pidbInitialize->Initialize(); |
| 133 | ExitOnFailure(hr, "failed to initialize connection to database: %ls", wzDatabase); | 148 | SqlExitOnFailure(hr, "failed to initialize connection to database: %ls", wzDatabase); |
| 134 | 149 | ||
| 135 | hr = pidbInitialize->QueryInterface(IID_IDBCreateSession, (LPVOID*)ppidbSession); | 150 | hr = pidbInitialize->QueryInterface(IID_IDBCreateSession, (LPVOID*)ppidbSession); |
| 136 | 151 | ||
| @@ -163,10 +178,10 @@ extern "C" HRESULT DAPI SqlStartTransaction( | |||
| 163 | HRESULT hr = S_OK; | 178 | HRESULT hr = S_OK; |
| 164 | 179 | ||
| 165 | hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)ppidbCommand); | 180 | hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)ppidbCommand); |
| 166 | ExitOnFailure(hr, "unable to create command from session"); | 181 | SqlExitOnFailure(hr, "unable to create command from session"); |
| 167 | 182 | ||
| 168 | hr = (*ppidbCommand)->QueryInterface(IID_ITransactionLocal, (LPVOID*)ppit); | 183 | hr = (*ppidbCommand)->QueryInterface(IID_ITransactionLocal, (LPVOID*)ppit); |
| 169 | ExitOnFailure(hr, "Unable to QueryInterface session to get ITransactionLocal"); | 184 | SqlExitOnFailure(hr, "Unable to QueryInterface session to get ITransactionLocal"); |
| 170 | 185 | ||
| 171 | hr = ((ITransactionLocal*)*ppit)->StartTransaction(ISOLATIONLEVEL_SERIALIZABLE, 0, NULL, NULL); | 186 | hr = ((ITransactionLocal*)*ppit)->StartTransaction(ISOLATIONLEVEL_SERIALIZABLE, 0, NULL, NULL); |
| 172 | 187 | ||
| @@ -192,12 +207,12 @@ extern "C" HRESULT DAPI SqlEndTransaction( | |||
| 192 | if (fCommit) | 207 | if (fCommit) |
| 193 | { | 208 | { |
| 194 | hr = pit->Commit(FALSE, XACTTC_SYNC, 0); | 209 | hr = pit->Commit(FALSE, XACTTC_SYNC, 0); |
| 195 | ExitOnFailure(hr, "commit of transaction failed"); | 210 | SqlExitOnFailure(hr, "commit of transaction failed"); |
| 196 | } | 211 | } |
| 197 | else | 212 | else |
| 198 | { | 213 | { |
| 199 | hr = pit->Abort(NULL, FALSE, FALSE); | 214 | hr = pit->Abort(NULL, FALSE, FALSE); |
| 200 | ExitOnFailure(hr, "abort of transaction failed"); | 215 | SqlExitOnFailure(hr, "abort of transaction failed"); |
| 201 | } | 216 | } |
| 202 | 217 | ||
| 203 | LExit: | 218 | LExit: |
| @@ -231,7 +246,7 @@ extern "C" HRESULT DAPI SqlDatabaseExists( | |||
| 231 | IDBCreateSession* pidbSession = NULL; | 246 | IDBCreateSession* pidbSession = NULL; |
| 232 | 247 | ||
| 233 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); | 248 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); |
| 234 | ExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); | 249 | SqlExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); |
| 235 | 250 | ||
| 236 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); | 251 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); |
| 237 | 252 | ||
| @@ -271,17 +286,17 @@ extern "C" HRESULT DAPI SqlSessionDatabaseExists( | |||
| 271 | // query to see if the database exists | 286 | // query to see if the database exists |
| 272 | // | 287 | // |
| 273 | hr = StrAllocFormatted(&pwzQuery, L"SELECT name FROM sysdatabases WHERE name='%s'", wzDatabase); | 288 | hr = StrAllocFormatted(&pwzQuery, L"SELECT name FROM sysdatabases WHERE name='%s'", wzDatabase); |
| 274 | ExitOnFailure(hr, "failed to allocate query string to ensure database exists"); | 289 | SqlExitOnFailure(hr, "failed to allocate query string to ensure database exists"); |
| 275 | 290 | ||
| 276 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, &pirs, NULL, pbstrErrorDescription); | 291 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, &pirs, NULL, pbstrErrorDescription); |
| 277 | ExitOnFailure(hr, "failed to get database list from 'master' database"); | 292 | SqlExitOnFailure(hr, "failed to get database list from 'master' database"); |
| 278 | Assert(pirs); | 293 | Assert(pirs); |
| 279 | 294 | ||
| 280 | // | 295 | // |
| 281 | // check to see if the database was returned | 296 | // check to see if the database was returned |
| 282 | // | 297 | // |
| 283 | hr = pirs->GetNextRows(DB_NULL_HCHAPTER, 0, 1, &cRows, &prow); | 298 | hr = pirs->GetNextRows(DB_NULL_HCHAPTER, 0, 1, &cRows, &prow); |
| 284 | ExitOnFailure(hr, "failed to get row with database name"); | 299 | SqlExitOnFailure(hr, "failed to get row with database name"); |
| 285 | 300 | ||
| 286 | // succeeded but no database | 301 | // succeeded but no database |
| 287 | if ((DB_S_ENDOFROWSET == hr) || (0 == cRows)) | 302 | if ((DB_S_ENDOFROWSET == hr) || (0 == cRows)) |
| @@ -324,10 +339,10 @@ extern "C" HRESULT DAPI SqlDatabaseEnsureExists( | |||
| 324 | // connect to the master database to create the new database | 339 | // connect to the master database to create the new database |
| 325 | // | 340 | // |
| 326 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); | 341 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); |
| 327 | ExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); | 342 | SqlExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); |
| 328 | 343 | ||
| 329 | hr = SqlSessionDatabaseEnsureExists(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); | 344 | hr = SqlSessionDatabaseEnsureExists(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); |
| 330 | ExitOnFailure(hr, "failed to create database: %ls", wzDatabase); | 345 | SqlExitOnFailure(hr, "failed to create database: %ls", wzDatabase); |
| 331 | 346 | ||
| 332 | Assert(S_OK == hr); | 347 | Assert(S_OK == hr); |
| 333 | LExit: | 348 | LExit: |
| @@ -355,12 +370,12 @@ extern "C" HRESULT DAPI SqlSessionDatabaseEnsureExists( | |||
| 355 | HRESULT hr = S_OK; | 370 | HRESULT hr = S_OK; |
| 356 | 371 | ||
| 357 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); | 372 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); |
| 358 | ExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase); | 373 | SqlExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase); |
| 359 | 374 | ||
| 360 | if (S_FALSE == hr) | 375 | if (S_FALSE == hr) |
| 361 | { | 376 | { |
| 362 | hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); | 377 | hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); |
| 363 | ExitOnFailure(hr, "failed to create database: %1", wzDatabase); | 378 | SqlExitOnFailure(hr, "failed to create database: %ls", wzDatabase); |
| 364 | } | 379 | } |
| 365 | // else database already exists, return S_FALSE | 380 | // else database already exists, return S_FALSE |
| 366 | 381 | ||
| @@ -398,10 +413,10 @@ extern "C" HRESULT DAPI SqlCreateDatabase( | |||
| 398 | // connect to the master database to create the new database | 413 | // connect to the master database to create the new database |
| 399 | // | 414 | // |
| 400 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); | 415 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); |
| 401 | ExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); | 416 | SqlExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); |
| 402 | 417 | ||
| 403 | hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); | 418 | hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); |
| 404 | ExitOnFailure(hr, "failed to create database: %ls", wzDatabase); | 419 | SqlExitOnFailure(hr, "failed to create database: %ls", wzDatabase); |
| 405 | 420 | ||
| 406 | Assert(S_OK == hr); | 421 | Assert(S_OK == hr); |
| 407 | LExit: | 422 | LExit: |
| @@ -433,23 +448,23 @@ extern "C" HRESULT DAPI SqlSessionCreateDatabase( | |||
| 433 | if (psfDatabase) | 448 | if (psfDatabase) |
| 434 | { | 449 | { |
| 435 | hr = FileSpecToString(psfDatabase, &pwzDbFile); | 450 | hr = FileSpecToString(psfDatabase, &pwzDbFile); |
| 436 | ExitOnFailure(hr, "failed to convert db filespec to string"); | 451 | SqlExitOnFailure(hr, "failed to convert db filespec to string"); |
| 437 | } | 452 | } |
| 438 | 453 | ||
| 439 | if (psfLog) | 454 | if (psfLog) |
| 440 | { | 455 | { |
| 441 | hr = FileSpecToString(psfLog, &pwzLogFile); | 456 | hr = FileSpecToString(psfLog, &pwzLogFile); |
| 442 | ExitOnFailure(hr, "failed to convert log filespec to string"); | 457 | SqlExitOnFailure(hr, "failed to convert log filespec to string"); |
| 443 | } | 458 | } |
| 444 | 459 | ||
| 445 | hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped); | 460 | hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped); |
| 446 | ExitOnFailure(hr, "failed to escape database string"); | 461 | SqlExitOnFailure(hr, "failed to escape database string"); |
| 447 | 462 | ||
| 448 | hr = StrAllocFormatted(&pwzQuery, L"CREATE DATABASE %s %s%s %s%s", pwzDatabaseEscaped, pwzDbFile ? L"ON " : L"", pwzDbFile ? pwzDbFile : L"", pwzLogFile ? L"LOG ON " : L"", pwzLogFile ? pwzLogFile : L""); | 463 | hr = StrAllocFormatted(&pwzQuery, L"CREATE DATABASE %s %s%s %s%s", pwzDatabaseEscaped, pwzDbFile ? L"ON " : L"", pwzDbFile ? pwzDbFile : L"", pwzLogFile ? L"LOG ON " : L"", pwzLogFile ? pwzLogFile : L""); |
| 449 | ExitOnFailure(hr, "failed to allocate query to create database: %ls", pwzDatabaseEscaped); | 464 | SqlExitOnFailure(hr, "failed to allocate query to create database: %ls", pwzDatabaseEscaped); |
| 450 | 465 | ||
| 451 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription); | 466 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription); |
| 452 | ExitOnFailure(hr, "failed to create database: %ls, Query: %ls", pwzDatabaseEscaped, pwzQuery); | 467 | SqlExitOnFailure(hr, "failed to create database: %ls, Query: %ls", pwzDatabaseEscaped, pwzQuery); |
| 453 | 468 | ||
| 454 | LExit: | 469 | LExit: |
| 455 | ReleaseStr(pwzQuery); | 470 | ReleaseStr(pwzQuery); |
| @@ -486,7 +501,7 @@ extern "C" HRESULT DAPI SqlDropDatabase( | |||
| 486 | // connect to the master database to search for wzDatabase | 501 | // connect to the master database to search for wzDatabase |
| 487 | // | 502 | // |
| 488 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); | 503 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); |
| 489 | ExitOnFailure(hr, "Failed to connect to 'master' database"); | 504 | SqlExitOnFailure(hr, "Failed to connect to 'master' database"); |
| 490 | 505 | ||
| 491 | hr = SqlSessionDropDatabase(pidbSession, wzDatabase, pbstrErrorDescription); | 506 | hr = SqlSessionDropDatabase(pidbSession, wzDatabase, pbstrErrorDescription); |
| 492 | 507 | ||
| @@ -515,18 +530,18 @@ extern "C" HRESULT DAPI SqlSessionDropDatabase( | |||
| 515 | LPWSTR pwzDatabaseEscaped = NULL; | 530 | LPWSTR pwzDatabaseEscaped = NULL; |
| 516 | 531 | ||
| 517 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); | 532 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); |
| 518 | ExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase); | 533 | SqlExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase); |
| 519 | 534 | ||
| 520 | hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped); | 535 | hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped); |
| 521 | ExitOnFailure(hr, "failed to escape database string"); | 536 | SqlExitOnFailure(hr, "failed to escape database string"); |
| 522 | 537 | ||
| 523 | if (S_OK == hr) | 538 | if (S_OK == hr) |
| 524 | { | 539 | { |
| 525 | hr = StrAllocFormatted(&pwzQuery, L"DROP DATABASE %s", pwzDatabaseEscaped); | 540 | hr = StrAllocFormatted(&pwzQuery, L"DROP DATABASE %s", pwzDatabaseEscaped); |
| 526 | ExitOnFailure(hr, "failed to allocate query to drop database: %ls", pwzDatabaseEscaped); | 541 | SqlExitOnFailure(hr, "failed to allocate query to drop database: %ls", pwzDatabaseEscaped); |
| 527 | 542 | ||
| 528 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription); | 543 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription); |
| 529 | ExitOnFailure(hr, "Failed to drop database"); | 544 | SqlExitOnFailure(hr, "Failed to drop database"); |
| 530 | } | 545 | } |
| 531 | 546 | ||
| 532 | LExit: | 547 | LExit: |
| @@ -567,23 +582,23 @@ extern "C" HRESULT DAPI SqlSessionExecuteQuery( | |||
| 567 | // create the command | 582 | // create the command |
| 568 | // | 583 | // |
| 569 | hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)&pidbCommand); | 584 | hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)&pidbCommand); |
| 570 | ExitOnFailure(hr, "failed to create database session"); | 585 | SqlExitOnFailure(hr, "failed to create database session"); |
| 571 | hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd); | 586 | hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd); |
| 572 | ExitOnFailure(hr, "failed to create command to execute session"); | 587 | SqlExitOnFailure(hr, "failed to create command to execute session"); |
| 573 | 588 | ||
| 574 | // | 589 | // |
| 575 | // set the sql text into the command | 590 | // set the sql text into the command |
| 576 | // | 591 | // |
| 577 | hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText); | 592 | hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText); |
| 578 | ExitOnFailure(hr, "failed to get command text object for command"); | 593 | SqlExitOnFailure(hr, "failed to get command text object for command"); |
| 579 | hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql); | 594 | hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql); |
| 580 | ExitOnFailure(hr, "failed to set SQL string: %ls", wzSql); | 595 | SqlExitOnFailure(hr, "failed to set SQL string: %ls", wzSql); |
| 581 | 596 | ||
| 582 | // | 597 | // |
| 583 | // execute the command | 598 | // execute the command |
| 584 | // | 599 | // |
| 585 | hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs)); | 600 | hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs)); |
| 586 | ExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql); | 601 | SqlExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql); |
| 587 | 602 | ||
| 588 | if (DB_S_ERRORSOCCURRED == hr) | 603 | if (DB_S_ERRORSOCCURRED == hr) |
| 589 | { | 604 | { |
| @@ -642,21 +657,21 @@ extern "C" HRESULT DAPI SqlCommandExecuteQuery( | |||
| 642 | // create the command | 657 | // create the command |
| 643 | // | 658 | // |
| 644 | hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd); | 659 | hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd); |
| 645 | ExitOnFailure(hr, "failed to create command to execute session"); | 660 | SqlExitOnFailure(hr, "failed to create command to execute session"); |
| 646 | 661 | ||
| 647 | // | 662 | // |
| 648 | // set the sql text into the command | 663 | // set the sql text into the command |
| 649 | // | 664 | // |
| 650 | hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText); | 665 | hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText); |
| 651 | ExitOnFailure(hr, "failed to get command text object for command"); | 666 | SqlExitOnFailure(hr, "failed to get command text object for command"); |
| 652 | hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql); | 667 | hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql); |
| 653 | ExitOnFailure(hr, "failed to set SQL string: %ls", wzSql); | 668 | SqlExitOnFailure(hr, "failed to set SQL string: %ls", wzSql); |
| 654 | 669 | ||
| 655 | // | 670 | // |
| 656 | // execute the command | 671 | // execute the command |
| 657 | // | 672 | // |
| 658 | hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs)); | 673 | hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs)); |
| 659 | ExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql); | 674 | SqlExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql); |
| 660 | 675 | ||
| 661 | if (DB_S_ERRORSOCCURRED == hr) | 676 | if (DB_S_ERRORSOCCURRED == hr) |
| 662 | { | 677 | { |
| @@ -700,14 +715,14 @@ extern "C" HRESULT DAPI SqlGetErrorInfo( | |||
| 700 | 715 | ||
| 701 | // only ask for error information if the interface supports it. | 716 | // only ask for error information if the interface supports it. |
| 702 | hr = pObjectWithError->QueryInterface(IID_ISupportErrorInfo,(void**)&pISupportErrorInfo); | 717 | hr = pObjectWithError->QueryInterface(IID_ISupportErrorInfo,(void**)&pISupportErrorInfo); |
| 703 | ExitOnFailure(hr, "No error information was found for object."); | 718 | SqlExitOnFailure(hr, "No error information was found for object."); |
| 704 | 719 | ||
| 705 | hr = pISupportErrorInfo->InterfaceSupportsErrorInfo(IID_InterfaceWithError); | 720 | hr = pISupportErrorInfo->InterfaceSupportsErrorInfo(IID_InterfaceWithError); |
| 706 | ExitOnFailure(hr, "InterfaceWithError is not supported for object with error"); | 721 | SqlExitOnFailure(hr, "InterfaceWithError is not supported for object with error"); |
| 707 | 722 | ||
| 708 | // ignore the return of GetErrorInfo it can succeed and return a NULL pointer in pIErrorInfoAll anyway | 723 | // ignore the return of GetErrorInfo it can succeed and return a NULL pointer in pIErrorInfoAll anyway |
| 709 | hr = ::GetErrorInfo(0, &pIErrorInfoAll); | 724 | hr = ::GetErrorInfo(0, &pIErrorInfoAll); |
| 710 | ExitOnFailure(hr, "failed to get error info"); | 725 | SqlExitOnFailure(hr, "failed to get error info"); |
| 711 | 726 | ||
| 712 | if (S_OK == hr && pIErrorInfoAll) | 727 | if (S_OK == hr && pIErrorInfoAll) |
| 713 | { | 728 | { |
| @@ -787,37 +802,37 @@ static HRESULT FileSpecToString( | |||
| 787 | LPWSTR pwz = NULL; | 802 | LPWSTR pwz = NULL; |
| 788 | 803 | ||
| 789 | hr = StrAllocString(&pwz, L"(", 1024); | 804 | hr = StrAllocString(&pwz, L"(", 1024); |
| 790 | ExitOnFailure(hr, "failed to allocate string for database file info"); | 805 | SqlExitOnFailure(hr, "failed to allocate string for database file info"); |
| 791 | 806 | ||
| 792 | ExitOnNull(*psf->wzName, hr, E_INVALIDARG, "logical name not specified in database file info"); | 807 | SqlExitOnNull(*psf->wzName, hr, E_INVALIDARG, "logical name not specified in database file info"); |
| 793 | ExitOnNull(*psf->wzFilename, hr, E_INVALIDARG, "filename not specified in database file info"); | 808 | SqlExitOnNull(*psf->wzFilename, hr, E_INVALIDARG, "filename not specified in database file info"); |
| 794 | 809 | ||
| 795 | hr = StrAllocFormatted(&pwz, L"%sNAME=%s", pwz, psf->wzName); | 810 | hr = StrAllocFormatted(&pwz, L"%sNAME=%s", pwz, psf->wzName); |
| 796 | ExitOnFailure(hr, "failed to format database file info name: %ls", psf->wzName); | 811 | SqlExitOnFailure(hr, "failed to format database file info name: %ls", psf->wzName); |
| 797 | 812 | ||
| 798 | hr = StrAllocFormatted(&pwz, L"%s, FILENAME='%s'", pwz, psf->wzFilename); | 813 | hr = StrAllocFormatted(&pwz, L"%s, FILENAME='%s'", pwz, psf->wzFilename); |
| 799 | ExitOnFailure(hr, "failed to format database file info filename: %ls", psf->wzFilename); | 814 | SqlExitOnFailure(hr, "failed to format database file info filename: %ls", psf->wzFilename); |
| 800 | 815 | ||
| 801 | if (0 != psf->wzSize[0]) | 816 | if (0 != psf->wzSize[0]) |
| 802 | { | 817 | { |
| 803 | hr = StrAllocFormatted(&pwz, L"%s, SIZE=%s", pwz, psf->wzSize); | 818 | hr = StrAllocFormatted(&pwz, L"%s, SIZE=%s", pwz, psf->wzSize); |
| 804 | ExitOnFailure(hr, "failed to format database file info size: %s", psf->wzSize); | 819 | SqlExitOnFailure(hr, "failed to format database file info size: %ls", psf->wzSize); |
| 805 | } | 820 | } |
| 806 | 821 | ||
| 807 | if (0 != psf->wzMaxSize[0]) | 822 | if (0 != psf->wzMaxSize[0]) |
| 808 | { | 823 | { |
| 809 | hr = StrAllocFormatted(&pwz, L"%s, MAXSIZE=%s", pwz, psf->wzMaxSize); | 824 | hr = StrAllocFormatted(&pwz, L"%s, MAXSIZE=%s", pwz, psf->wzMaxSize); |
| 810 | ExitOnFailure(hr, "failed to format database file info maxsize: %s", psf->wzMaxSize); | 825 | SqlExitOnFailure(hr, "failed to format database file info maxsize: %ls", psf->wzMaxSize); |
| 811 | } | 826 | } |
| 812 | 827 | ||
| 813 | if (0 != psf->wzGrow[0]) | 828 | if (0 != psf->wzGrow[0]) |
| 814 | { | 829 | { |
| 815 | hr = StrAllocFormatted(&pwz, L"%s, FILEGROWTH=%s", pwz, psf->wzGrow); | 830 | hr = StrAllocFormatted(&pwz, L"%s, FILEGROWTH=%s", pwz, psf->wzGrow); |
| 816 | ExitOnFailure(hr, "failed to format database file info growth: %s", psf->wzGrow); | 831 | SqlExitOnFailure(hr, "failed to format database file info growth: %ls", psf->wzGrow); |
| 817 | } | 832 | } |
| 818 | 833 | ||
| 819 | hr = StrAllocFormatted(&pwz, L"%s)", pwz); | 834 | hr = StrAllocFormatted(&pwz, L"%s)", pwz); |
| 820 | ExitOnFailure(hr, "failed to allocate string for file spec"); | 835 | SqlExitOnFailure(hr, "failed to allocate string for file spec"); |
| 821 | 836 | ||
| 822 | *ppwz = pwz; | 837 | *ppwz = pwz; |
| 823 | pwz = NULL; // null here so it doesn't get freed below | 838 | pwz = NULL; // null here so it doesn't get freed below |
| @@ -850,13 +865,13 @@ static HRESULT EscapeSqlIdentifier( | |||
| 850 | if (cchIdentifier == 0 || (wzIdentifier[0] == '[' && wzIdentifier[cchIdentifier-1] == ']')) | 865 | if (cchIdentifier == 0 || (wzIdentifier[0] == '[' && wzIdentifier[cchIdentifier-1] == ']')) |
| 851 | { | 866 | { |
| 852 | hr = StrAllocString(&pwz, wzIdentifier, 0); | 867 | hr = StrAllocString(&pwz, wzIdentifier, 0); |
| 853 | ExitOnFailure(hr, "failed to format database name: %ls", wzIdentifier); | 868 | SqlExitOnFailure(hr, "failed to format database name: %ls", wzIdentifier); |
| 854 | } | 869 | } |
| 855 | else | 870 | else |
| 856 | { | 871 | { |
| 857 | //escape it | 872 | //escape it |
| 858 | hr = StrAllocFormatted(&pwz, L"[%s]", wzIdentifier); | 873 | hr = StrAllocFormatted(&pwz, L"[%s]", wzIdentifier); |
| 859 | ExitOnFailure(hr, "failed to format escaped database name: %ls", wzIdentifier); | 874 | SqlExitOnFailure(hr, "failed to format escaped database name: %ls", wzIdentifier); |
| 860 | } | 875 | } |
| 861 | 876 | ||
| 862 | *ppwz = pwz; | 877 | *ppwz = pwz; |
