/ Allocate record set and execute an SQL query. */ /
| 1425 | /* Allocate record set and execute an SQL query. */ |
| 1426 | /***********************************************************************/ |
| 1427 | int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols) |
| 1428 | { |
| 1429 | PGLOBAL& g = m_G; |
| 1430 | void *buffer; |
| 1431 | bool b; |
| 1432 | UWORD n, k; |
| 1433 | SWORD len, tp, ncol = 0; |
| 1434 | ODBCCOL *colp; |
| 1435 | RETCODE rc; |
| 1436 | HSTMT hstmt; |
| 1437 | |
| 1438 | try { |
| 1439 | b = false; |
| 1440 | |
| 1441 | if (m_hstmt) { |
| 1442 | // This is a Requery |
| 1443 | rc = SQLFreeStmt(m_hstmt, SQL_CLOSE); |
| 1444 | |
| 1445 | if (!Check(rc)) |
| 1446 | ThrowDBX(rc, "SQLFreeStmt", m_hstmt); |
| 1447 | |
| 1448 | m_hstmt = NULL; |
| 1449 | } // endif m_hstmt |
| 1450 | |
| 1451 | rc = SQLAllocStmt(m_hdbc, &hstmt); |
| 1452 | |
| 1453 | if (!Check(rc)) |
| 1454 | ThrowDBX(rc, "SQLAllocStmt"); |
| 1455 | |
| 1456 | if (m_Scrollable) { |
| 1457 | rc = SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_SCROLLABLE, |
| 1458 | (void*)SQL_SCROLLABLE, 0); |
| 1459 | |
| 1460 | if (!Check(rc)) |
| 1461 | ThrowDBX(rc, "Scrollable", hstmt); |
| 1462 | |
| 1463 | } // endif m_Scrollable |
| 1464 | |
| 1465 | OnSetOptions(hstmt); |
| 1466 | b = true; |
| 1467 | |
| 1468 | if (trace(1)) |
| 1469 | htrc("ExecDirect hstmt=%p %.256s\n", hstmt, sql); |
| 1470 | |
| 1471 | if (m_Tdb->Srcdef) { |
| 1472 | // Be sure this is a query returning a result set |
| 1473 | do { |
| 1474 | rc = SQLPrepare(hstmt, (PUCHAR)sql, SQL_NTS); |
| 1475 | } while (rc == SQL_STILL_EXECUTING); |
| 1476 | |
| 1477 | if (!Check(rc)) |
| 1478 | ThrowDBX(rc, "SQLPrepare", hstmt); |
| 1479 | |
| 1480 | if (!Check(rc = SQLNumResultCols(hstmt, &ncol))) |
| 1481 | ThrowDBX(rc, "SQLNumResultCols", hstmt); |
| 1482 | |
| 1483 | if (ncol == 0) { |
| 1484 | snprintf(g->Message, sizeof(g->Message), "This Srcdef does not return a result set"); |
no test coverage detected