/ GetMetaData: constructs the result blocks containing the */ description of all the columns of an SQL command. */ /
| 1968 | /* description of all the columns of an SQL command. */ |
| 1969 | /**************************************************************************/ |
| 1970 | PQRYRES ODBConn::GetMetaData(PGLOBAL g, PCSZ dsn, PCSZ src) |
| 1971 | { |
| 1972 | static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_INT, |
| 1973 | TYPE_SHORT, TYPE_SHORT}; |
| 1974 | static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_PREC, |
| 1975 | FLD_SCALE, FLD_NULL}; |
| 1976 | static unsigned int length[] = {0, 6, 10, 6, 6}; |
| 1977 | unsigned char cn[60]; |
| 1978 | int qcol = 5; |
| 1979 | short nl, type, prec, nul, cns = (short)sizeof(cn); |
| 1980 | PQRYRES qrp = NULL; |
| 1981 | PCOLRES crp; |
| 1982 | USHORT i; |
| 1983 | SQLULEN n; |
| 1984 | SWORD ncol; |
| 1985 | RETCODE rc; |
| 1986 | HSTMT hstmt; |
| 1987 | |
| 1988 | try { |
| 1989 | rc = SQLAllocStmt(m_hdbc, &hstmt); |
| 1990 | |
| 1991 | if (!Check(rc)) |
| 1992 | ThrowDBX(SQL_INVALID_HANDLE, "SQLAllocStmt"); |
| 1993 | |
| 1994 | OnSetOptions(hstmt); |
| 1995 | |
| 1996 | do { |
| 1997 | rc = SQLPrepare(hstmt, (PUCHAR)src, SQL_NTS); |
| 1998 | // rc = SQLExecDirect(hstmt, (PUCHAR)src, SQL_NTS); |
| 1999 | } while (rc == SQL_STILL_EXECUTING); |
| 2000 | |
| 2001 | if (!Check(rc)) |
| 2002 | ThrowDBX(rc, "SQLExecDirect", hstmt); |
| 2003 | |
| 2004 | do { |
| 2005 | rc = SQLNumResultCols(hstmt, &ncol); |
| 2006 | } while (rc == SQL_STILL_EXECUTING); |
| 2007 | |
| 2008 | if (!Check(rc)) |
| 2009 | ThrowDBX(rc, "SQLNumResultCols", hstmt); |
| 2010 | |
| 2011 | if (ncol) for (i = 1; i <= ncol; i++) { |
| 2012 | do { |
| 2013 | rc = SQLDescribeCol(hstmt, i, NULL, 0, &nl, NULL, NULL, NULL, NULL); |
| 2014 | } while (rc == SQL_STILL_EXECUTING); |
| 2015 | |
| 2016 | if (!Check(rc)) |
| 2017 | ThrowDBX(rc, "SQLDescribeCol", hstmt); |
| 2018 | |
| 2019 | length[0] = MY_MAX(length[0], (UINT)nl); |
| 2020 | } // endfor i |
| 2021 | |
| 2022 | } catch(DBX *x) { |
| 2023 | snprintf(g->Message, sizeof(g->Message), "%s: %s", x->m_Msg, x->GetErrorMessage(0)); |
| 2024 | goto err; |
| 2025 | } // end try/catch |
| 2026 | |
| 2027 | if (!ncol) { |
no test coverage detected