SQLRETURN SQL_API
SQLColAttributes(SQLHSTMT StatementHandle,
		 SQLUSMALLINT ColumnNumber,
		 SQLUSMALLINT FieldIdentifier,
		 SQLPOINTER CharacterAttributePtr,
		 SQLSMALLINT BufferLength,
		 SQLSMALLINT *StringLengthPtr,
		 SQLLEN *NumericAttributePtr)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLColAttributes " PTRFMT " %u %s\n",
		PTRFMTCAST StatementHandle,
		(unsigned int) ColumnNumber,
		translateFieldIdentifier(FieldIdentifier));
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	return SQLColAttributes_(stmt,
				 ColumnNumber,
				 FieldIdentifier,
				 CharacterAttributePtr,
				 BufferLength,
				 StringLengthPtr,
				 NumericAttributePtr);
}
Exemple #2
0
SQLRETURN SQL_API
SQLRowCount(SQLHSTMT StatementHandle,
	    SQLLEN *RowCountPtr)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLRowCount %p\n", StatementHandle);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	/* check statement cursor state, query should be executed */
	if (stmt->State < EXECUTED0) {
		/* Function sequence error */
		addStmtError(stmt, "HY010", NULL, 0);
		return SQL_ERROR;
	}

	/* check output parameter */
	if (RowCountPtr == NULL) {
		/* Invalid use of null pointer */
		addStmtError(stmt, "HY009", NULL, 0);
		return SQL_ERROR;
	}

	/* We can now set the "number of result set rows" value */
	*RowCountPtr = (SQLLEN) stmt->rowcount;

	return SQL_SUCCESS;
}
Exemple #3
0
SQLRETURN SQL_API
SQLColAttribute(SQLHSTMT StatementHandle,
		SQLUSMALLINT ColumnNumber,
		SQLUSMALLINT FieldIdentifier,
		SQLPOINTER CharacterAttributePtr,
		SQLSMALLINT BufferLength,
		SQLSMALLINT *StringLengthPtr,
		LENP_OR_POINTER_T NumericAttributePtr)
{
#ifdef ODBCDEBUG
	ODBCLOG("SQLColAttribute " PTRFMT " %s\n",
		PTRFMTCAST StatementHandle,
		translateFieldIdentifier(FieldIdentifier));
#endif

	if (!isValidStmt((ODBCStmt *) StatementHandle))
		return SQL_INVALID_HANDLE;

	clearStmtErrors((ODBCStmt *) StatementHandle);

	return SQLColAttribute_((ODBCStmt *) StatementHandle,
				ColumnNumber,
				FieldIdentifier,
				CharacterAttributePtr,
				BufferLength,
				StringLengthPtr,
				NumericAttributePtr);
}
Exemple #4
0
SQLRETURN SQL_API
SQLSetParam(SQLHSTMT StatementHandle,
	    SQLUSMALLINT ParameterNumber,
	    SQLSMALLINT ValueType,
	    SQLSMALLINT ParameterType,
	    SQLULEN LengthPrecision,
	    SQLSMALLINT ParameterScale,
	    SQLPOINTER ParameterValue,
	    SQLLEN *StrLen_or_Ind)
{
#ifdef ODBCDEBUG
	ODBCLOG("SQLSetParam " PTRFMT " %u %s %s " ULENFMT " %d\n",
		PTRFMTCAST StatementHandle, (unsigned int) ParameterNumber,
		translateCType(ValueType),
		translateSQLType(ParameterType),
		ULENCAST LengthPrecision, (int) ParameterScale);
#endif

	/* map this call to SQLBindParameter as described in ODBC 3.0 SDK help */
	return SQLBindParameter_((ODBCStmt *) StatementHandle,
				 ParameterNumber,
				 SQL_PARAM_INPUT_OUTPUT,
				 ValueType,
				 ParameterType,
				 LengthPrecision,
				 ParameterScale,
				 ParameterValue,
				 SQL_SETPARAM_VALUE_MAX,
				 StrLen_or_Ind);
}
Exemple #5
0
SQLRETURN SQL_API
SQLGetStmtAttrW(SQLHSTMT StatementHandle,
                SQLINTEGER Attribute,
                SQLPOINTER ValuePtr,
                SQLINTEGER BufferLength,
                SQLINTEGER *StringLengthPtr)
{
#ifdef ODBCDEBUG
    ODBCLOG("SQLGetStmtAttrW " PTRFMT " %s " PTRFMT " %d " PTRFMT "\n",
            PTRFMTCAST StatementHandle, translateStmtAttribute(Attribute),
            PTRFMTCAST ValuePtr, (int) BufferLength,
            PTRFMTCAST StringLengthPtr);
#endif

    if (!isValidStmt((ODBCStmt *) StatementHandle))
        return SQL_INVALID_HANDLE;

    clearStmtErrors((ODBCStmt *) StatementHandle);

    /* there are no string-valued attributes */

    return MNDBGetStmtAttr((ODBCStmt *) StatementHandle,
                           Attribute,
                           ValuePtr,
                           BufferLength,
                           StringLengthPtr);
}
Exemple #6
0
SQLRETURN SQL_API
SQLGetDiagRec(SQLSMALLINT HandleType,
	      SQLHANDLE Handle,
	      SQLSMALLINT RecNumber,
	      SQLCHAR *SQLState,
	      SQLINTEGER *NativeErrorPtr,
	      SQLCHAR *MessageText,
	      SQLSMALLINT BufferLength,
	      SQLSMALLINT *TextLengthPtr)
{
#ifdef ODBCDEBUG
	ODBCLOG("SQLGetDiagRec %s " PTRFMT " %d %d\n",
		HandleType == SQL_HANDLE_ENV ? "Env" : HandleType == SQL_HANDLE_DBC ? "Dbc" : HandleType == SQL_HANDLE_STMT ? "Stmt" : "Desc",
		PTRFMTCAST Handle, (int) RecNumber, (int) BufferLength);
#endif

	return MNDBGetDiagRec(HandleType,
			      Handle,
			      RecNumber,
			      SQLState,
			      NativeErrorPtr,
			      MessageText,
			      BufferLength,
			      TextLengthPtr);
}
Exemple #7
0
SQLRETURN SQL_API
SQLGetDiagField(SQLSMALLINT HandleType,
		SQLHANDLE Handle,
		SQLSMALLINT RecNumber,
		SQLSMALLINT DiagIdentifier,
		SQLPOINTER DiagInfoPtr,
		SQLSMALLINT BufferLength,
		SQLSMALLINT *StringLengthPtr)
{
#ifdef ODBCDEBUG
	ODBCLOG("SQLGetDiagField %s %p %d %s %p %d %p\n",
		HandleType == SQL_HANDLE_ENV ? "Env" : HandleType == SQL_HANDLE_DBC ? "Dbc" : HandleType == SQL_HANDLE_STMT ? "Stmt" : "Desc",
		Handle, (int) RecNumber,
		translateDiagIdentifier(DiagIdentifier),
		DiagInfoPtr,
		(int) BufferLength, StringLengthPtr);
#endif

	return MNDBGetDiagField(HandleType,
				Handle,
				RecNumber,
				DiagIdentifier,
				DiagInfoPtr,
				BufferLength,
				StringLengthPtr);
}
Exemple #8
0
SQLRETURN SQL_API
SQLFetchScroll(SQLHSTMT StatementHandle,
	       SQLSMALLINT FetchOrientation,
	       SQLLEN FetchOffset)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLFetchScroll %p %s " LENFMT "\n",
		StatementHandle,
		translateFetchOrientation(FetchOrientation),
		LENCAST FetchOffset);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	/* check statement cursor state, query should be executed */
	if (stmt->State < EXECUTED0 || stmt->State == EXTENDEDFETCHED) {
		/* Function sequence error */
		addStmtError(stmt, "HY010", NULL, 0);
		return SQL_ERROR;
	}
	if (stmt->State == EXECUTED0) {
		/* Invalid cursor state */
		addStmtError(stmt, "24000", NULL, 0);
		return SQL_ERROR;
	}

	return MNDBFetchScroll(stmt, FetchOrientation, FetchOffset,
			       stmt->ImplRowDescr->sql_desc_array_status_ptr);
}
SQLRETURN SQL_API
SQLForeignKeys(SQLHSTMT StatementHandle,
	       SQLCHAR *PKCatalogName,
	       SQLSMALLINT NameLength1,
	       SQLCHAR *PKSchemaName,
	       SQLSMALLINT NameLength2,
	       SQLCHAR *PKTableName,
	       SQLSMALLINT NameLength3,
	       SQLCHAR *FKCatalogName,
	       SQLSMALLINT NameLength4,
	       SQLCHAR *FKSchemaName,
	       SQLSMALLINT NameLength5,
	       SQLCHAR *FKTableName,
	       SQLSMALLINT NameLength6)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLForeignKeys " PTRFMT " ", PTRFMTCAST StatementHandle);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	return SQLForeignKeys_(stmt, PKCatalogName, NameLength1,
			       PKSchemaName, NameLength2,
			       PKTableName, NameLength3,
			       FKCatalogName, NameLength4,
			       FKSchemaName, NameLength5,
			       FKTableName, NameLength6);
}
Exemple #10
0
SQLRETURN SQL_API
SQLSpecialColumns(SQLHSTMT StatementHandle,
		  SQLUSMALLINT IdentifierType,
		  SQLCHAR *CatalogName,
		  SQLSMALLINT NameLength1,
		  SQLCHAR *SchemaName,
		  SQLSMALLINT NameLength2,
		  SQLCHAR *TableName,
		  SQLSMALLINT NameLength3,
		  SQLUSMALLINT Scope,
		  SQLUSMALLINT Nullable)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLSpecialColumns %p %s ",
		StatementHandle,
		translateIdentifierType(IdentifierType));
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	return MNDBSpecialColumns(stmt,
				  IdentifierType,
				  CatalogName, NameLength1,
				  SchemaName, NameLength2,
				  TableName, NameLength3,
				  Scope,
				  Nullable);
}
Exemple #11
0
SQLRETURN SQL_API
SQLColumns(SQLHSTMT StatementHandle,
	   SQLCHAR *CatalogName,
	   SQLSMALLINT NameLength1,
	   SQLCHAR *SchemaName,
	   SQLSMALLINT NameLength2,
	   SQLCHAR *TableName,
	   SQLSMALLINT NameLength3,
	   SQLCHAR *ColumnName,
	   SQLSMALLINT NameLength4)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLColumns " PTRFMT, PTRFMTCAST StatementHandle);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	return SQLColumns_(stmt,
			   CatalogName, NameLength1,
			   SchemaName, NameLength2,
			   TableName, NameLength3,
			   ColumnName, NameLength4);
}
Exemple #12
0
SQLRETURN SQL_API
SQLDataSources(SQLHENV EnvironmentHandle,
	       SQLUSMALLINT Direction,
	       SQLCHAR *ServerName,
	       SQLSMALLINT BufferLength1,
	       SQLSMALLINT *NameLength1,
	       SQLCHAR *Description,
	       SQLSMALLINT BufferLength2,
	       SQLSMALLINT *NameLength2)
{
	ODBCEnv *env = (ODBCEnv *) EnvironmentHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLDataSources " PTRFMT " %s\n",
		PTRFMTCAST EnvironmentHandle, translateDirection(Direction));
#endif

	if (!isValidEnv(env))
		return SQL_INVALID_HANDLE;

	clearEnvErrors(env);

	return MNDBDataSources(env, Direction,
			       ServerName, BufferLength1, NameLength1,
			       Description, BufferLength2, NameLength2);
}
Exemple #13
0
SQLRETURN SQL_API
SQLFetch(SQLHSTMT StatementHandle)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLFetch " PTRFMT "\n", PTRFMTCAST StatementHandle);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	assert(stmt->hdl);

	/* check statement cursor state, query should be executed */
	if (stmt->State < EXECUTED0 || stmt->State == EXTENDEDFETCHED) {
		/* Function sequence error */
		addStmtError(stmt, "HY010", NULL, 0);
		return SQL_ERROR;
	}
	if (stmt->State == EXECUTED0) {
		/* Invalid cursor state */
		addStmtError(stmt, "24000", NULL, 0);
		return SQL_ERROR;
	}

	stmt->startRow += stmt->rowSetSize;

	return MNDBFetch(stmt, stmt->ImplRowDescr->sql_desc_array_status_ptr);
}
Exemple #14
0
SQLRETURN SQL_API
SQLNumResultCols(SQLHSTMT StatementHandle,
		 SQLSMALLINT *ColumnCountPtr)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLNumResultCols " PTRFMT "\n", PTRFMTCAST StatementHandle);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	/* check statement cursor state, query should be prepared or executed */
	if (stmt->State == INITED) {
		/* Function sequence error */
		addStmtError(stmt, "HY010", NULL, 0);
		return SQL_ERROR;
	}

	/* check output parameter */
	if (ColumnCountPtr == NULL) {
		/* Invalid use of null pointer */
		addStmtError(stmt, "HY009", NULL, 0);
		return SQL_ERROR;
	}

	/* We can now set the "number of output columns" value */
	/* Note: row count can be 0 (for non SELECT queries) */
	*ColumnCountPtr = stmt->ImplRowDescr->sql_desc_count;

	return SQL_SUCCESS;
}
Exemple #15
0
SQLRETURN SQL_API
SQLProcedures(SQLHSTMT StatementHandle,
	      SQLCHAR *CatalogName,
	      SQLSMALLINT NameLength1,
	      SQLCHAR *SchemaName,
	      SQLSMALLINT NameLength2,
	      SQLCHAR *ProcName,
	      SQLSMALLINT NameLength3)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLProcedures " PTRFMT " ", PTRFMTCAST StatementHandle);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	return MNDBProcedures(stmt,
			      CatalogName, NameLength1,
			      SchemaName, NameLength2,
			      ProcName, NameLength3);
}
Exemple #16
0
SQLRETURN SQL_API
SQLGetConnectAttr(SQLHDBC ConnectionHandle,
		  SQLINTEGER Attribute,
		  SQLPOINTER ValuePtr,
		  SQLINTEGER BufferLength,
		  SQLINTEGER *StringLengthPtr)
{
#ifdef ODBCDEBUG
	ODBCLOG("SQLGetConnectAttr " PTRFMT " %s " PTRFMT " %d " PTRFMT "\n",
		PTRFMTCAST ConnectionHandle,
		translateConnectAttribute(Attribute),
		PTRFMTCAST ValuePtr, (int) BufferLength,
		PTRFMTCAST StringLengthPtr);
#endif

	if (!isValidDbc((ODBCDbc *) ConnectionHandle))
		return SQL_INVALID_HANDLE;

	clearDbcErrors((ODBCDbc *) ConnectionHandle);

	return MNDBGetConnectAttr((ODBCDbc *) ConnectionHandle,
				  Attribute,
				  ValuePtr,
				  BufferLength,
				  StringLengthPtr);
}
SQLRETURN SQL_API
SQLSetScrollOptions(SQLHSTMT StatementHandle,
		    SQLUSMALLINT fConcurrency,
		    SQLLEN crowKeyset,
		    SQLUSMALLINT crowRowset)
{
#ifdef ODBCDEBUG
	ODBCLOG("SQLSetScrollOptions " PTRFMT " %u " LENFMT " %u\n",
		PTRFMTCAST StatementHandle, (unsigned int) fConcurrency,
		LENCAST crowKeyset, (unsigned int) crowRowset);
#endif

	(void) fConcurrency;	/* Stefan: unused!? */
	(void) crowKeyset;	/* Stefan: unused!? */
	(void) crowRowset;	/* Stefan: unused!? */

	if (!isValidStmt((ODBCStmt *) StatementHandle))
		return SQL_INVALID_HANDLE;

	clearStmtErrors((ODBCStmt *) StatementHandle);

	/* TODO: implement the mapping to multiple SQLSetStmtAttr() calls */
	/* See ODBC 3.5 SDK Help file for details */

	/* for now return error */
	/* Driver does not support this function */
	addStmtError((ODBCStmt *) StatementHandle, "IM001", NULL, 0);
	return SQL_ERROR;
}
Exemple #18
0
SQLRETURN SQL_API
SQLGetDiagRecW(SQLSMALLINT HandleType,
	       SQLHANDLE Handle,
	       SQLSMALLINT RecNumber,
	       SQLWCHAR *SQLState,
	       SQLINTEGER *NativeErrorPtr,
	       SQLWCHAR *MessageText,
	       SQLSMALLINT BufferLength,
	       SQLSMALLINT *TextLengthPtr)
{
	SQLRETURN rc;
	SQLCHAR state[6];
	SQLCHAR msg[512];
	SQLSMALLINT n;

#ifdef ODBCDEBUG
	ODBCLOG("SQLGetDiagRecW %s " PTRFMT " %d %d\n",
		HandleType == SQL_HANDLE_ENV ? "Env" : HandleType == SQL_HANDLE_DBC ? "Dbc" : HandleType == SQL_HANDLE_STMT ? "Stmt" : "Desc",
		PTRFMTCAST Handle, (int) RecNumber, (int) BufferLength);
#endif


	rc = MNDBGetDiagRec(HandleType, Handle, RecNumber, state,
			    NativeErrorPtr, msg, (SQLSMALLINT) sizeof(msg), &n);
#ifdef ODBCDEBUG
	ODBCLOG("SQLGetDiagRecW: %s\n", SQL_SUCCEEDED(rc) ? (char *) msg : rc == SQL_NO_DATA ? "no error" : "failed");
#endif

	if (SQL_SUCCEEDED(rc)) {
		char *e = ODBCutf82wchar(state, 5, SQLState, 6, NULL);

		if (e)
			rc = SQL_ERROR;
	}

	if (SQL_SUCCEEDED(rc)) {
		char *e = ODBCutf82wchar(msg, n, MessageText,
					 BufferLength, &n);

		if (e)
			rc = SQL_ERROR;
		if (TextLengthPtr)
			*TextLengthPtr = n;
	}

	return rc;
}
Exemple #19
0
SQLRETURN SQL_API
SQLDescribeColW(SQLHSTMT StatementHandle,
		SQLUSMALLINT ColumnNumber,
		SQLWCHAR *ColumnName,
		SQLSMALLINT BufferLength,
		SQLSMALLINT *NameLengthPtr,
		SQLSMALLINT *DataTypePtr,
		SQLULEN *ColumnSizePtr,
		SQLSMALLINT *DecimalDigitsPtr,
		SQLSMALLINT *NullablePtr)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
	SQLCHAR *colname;
	SQLSMALLINT n;
	SQLRETURN rc = SQL_ERROR;

#ifdef ODBCDEBUG
	ODBCLOG("SQLDescribeColW " PTRFMT " %u " PTRFMT " %d " PTRFMT " " PTRFMT " " PTRFMT " " PTRFMT " " PTRFMT "\n",
		PTRFMTCAST StatementHandle, (unsigned int) ColumnNumber,
		PTRFMTCAST ColumnName, (int) BufferLength,
		PTRFMTCAST NameLengthPtr, PTRFMTCAST DataTypePtr,
		PTRFMTCAST ColumnSizePtr, PTRFMTCAST DecimalDigitsPtr,
		PTRFMTCAST NullablePtr);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	rc = MNDBDescribeCol(stmt, ColumnNumber, NULL, 0, &n, DataTypePtr,
			     ColumnSizePtr, DecimalDigitsPtr, NullablePtr);
	if (!SQL_SUCCEEDED(rc))
		return rc;
	clearStmtErrors(stmt);
	n++;			/* account for NUL byte */
	colname = malloc(n);
	if (colname == NULL) {
		/* Memory allocation error */
		addStmtError(stmt, "HY001", NULL, 0);
		return SQL_ERROR;
	}
	rc = MNDBDescribeCol(stmt,
			     ColumnNumber,
			     colname,
			     n,
			     &n,
			     DataTypePtr,
			     ColumnSizePtr,
			     DecimalDigitsPtr,
			     NullablePtr);
	if (SQL_SUCCEEDED(rc)) {
		fixWcharOut(rc, colname, n, ColumnName, BufferLength,
			    NameLengthPtr, 1, addStmtError, stmt);
	}
	free(colname);

	return rc;
}
Exemple #20
0
/*
 * Check if the statement handle is valid.
 * Note: this function is used internally by the driver to assert legal
 * and save usage of the handle and prevent crashes as much as possible.
 *
 * Precondition: none
 * Postcondition: returns 1 if it is a valid statement handle,
 * 	returns 0 if is invalid and thus an unusable handle.
 */
int
isValidStmt(ODBCStmt *stmt)
{
#ifdef ODBCDEBUG
	if (!(stmt &&stmt->Type == ODBC_STMT_MAGIC_NR))
		ODBCLOG("stmt " PTRFMT " not a valid statement handle\n", PTRFMTCAST stmt);
#endif
	return stmt &&stmt->Type == ODBC_STMT_MAGIC_NR;
}
Exemple #21
0
/*
 * Check if the connection handle is valid.
 * Note: this function is used internally by the driver to assert legal
 * and save usage of the handle and prevent crashes as much as possible.
 *
 * Precondition: none
 * Postcondition: returns 1 if it is a valid connection handle,
 * 	returns 0 if is invalid and thus an unusable handle.
 */
int
isValidDbc(ODBCDbc *dbc)
{
#ifdef ODBCDEBUG
	if (!(dbc && dbc->Type == ODBC_DBC_MAGIC_NR))
		ODBCLOG("dbc %p: not a valid connection handle\n", dbc);
#endif
	return dbc && dbc->Type == ODBC_DBC_MAGIC_NR;
}
Exemple #22
0
SQLRETURN SQL_API
SQLFreeEnv(SQLHENV EnvironmentHandle)
{
#ifdef ODBCDEBUG
	ODBCLOG("SQLFreeEnv " PTRFMT "\n", PTRFMTCAST EnvironmentHandle);
#endif

	/* use mapping as described in ODBC 3 SDK Help file */
	return SQLFreeHandle_(SQL_HANDLE_ENV, (SQLHANDLE) EnvironmentHandle);
}
Exemple #23
0
SQLRETURN SQL_API
SQLExtendedFetch(SQLHSTMT StatementHandle,
		 SQLUSMALLINT FetchOrientation,
		 SQLLEN FetchOffset,
#ifdef BUILD_REAL_64_BIT_MODE	/* note: only defined on Debian Lenny */
		 SQLUINTEGER  *RowCountPtr,
#else
		 SQLULEN *RowCountPtr,
#endif
		 SQLUSMALLINT *RowStatusArray)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
	SQLRETURN rc;

#ifdef ODBCDEBUG
	ODBCLOG("SQLExtendedFetch " PTRFMT " %s " LENFMT " " PTRFMT " " PTRFMT "\n",
		PTRFMTCAST StatementHandle,
		translateFetchOrientation(FetchOrientation),
		LENCAST FetchOffset, PTRFMTCAST RowCountPtr,
		PTRFMTCAST RowStatusArray);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	/* check statement cursor state, query should be executed */
	if (stmt->State < EXECUTED0 || stmt->State == FETCHED) {
		/* Function sequence error */
		addStmtError(stmt, "HY010", NULL, 0);
		return SQL_ERROR;
	}
	if (stmt->State == EXECUTED0) {
		/* Invalid cursor state */
		addStmtError(stmt, "24000", NULL, 0);
		return SQL_ERROR;
	}

	rc = MNDBFetchScroll(stmt, FetchOrientation, FetchOffset,
			     RowStatusArray);

	if (SQL_SUCCEEDED(rc) || rc == SQL_NO_DATA)
		stmt->State = EXTENDEDFETCHED;

	if (SQL_SUCCEEDED(rc) && RowCountPtr) {
#ifdef BUILD_REAL_64_BIT_MODE	/* note: only defined on Debian Lenny */
		WriteValue(RowCountPtr, (SQLUINTEGER) stmt->rowSetSize);
#else
		WriteValue(RowCountPtr, (SQLULEN) stmt->rowSetSize);
#endif
	}

	return rc;
}
Exemple #24
0
SQLRETURN SQL_API
SQLDataSourcesW(SQLHENV EnvironmentHandle,
		SQLUSMALLINT Direction,
		SQLWCHAR *ServerName,
		SQLSMALLINT BufferLength1,
		SQLSMALLINT *NameLength1,
		SQLWCHAR *Description,
		SQLSMALLINT BufferLength2,
		SQLSMALLINT *NameLength2)
{
	ODBCEnv *env = (ODBCEnv *) EnvironmentHandle;
	SQLRETURN rc;
	SQLCHAR *server, *descr;
	SQLSMALLINT length1, length2;

#ifdef ODBCDEBUG
	ODBCLOG("SQLDataSourcesW " PTRFMT " %s\n",
		PTRFMTCAST EnvironmentHandle, translateDirection(Direction));
#endif

	if (!isValidEnv(env))
		return SQL_INVALID_HANDLE;

	clearEnvErrors(env);

	server = malloc(100);
	descr = malloc(100);
	if (server == NULL || descr == NULL) {
		/* Memory allocation error */
		addEnvError(env, "HY001", NULL, 0);
		if (server)
			free(server);
		if (descr)
			free(descr);
		return SQL_ERROR;
	}

	rc = MNDBDataSources(env, Direction,
			     server, 100, &length1,
			     descr, 100, &length2);

	if (SQL_SUCCEEDED(rc)) {
		fixWcharOut(rc, server, length1,
			    ServerName, BufferLength1, NameLength1,
			    1, addEnvError, env);
		fixWcharOut(rc, descr, length2,
			    Description, BufferLength2, NameLength2,
			    1, addEnvError, env);
	}
	free(server);
	free(descr);

	return rc;
}
Exemple #25
0
SQLRETURN SQL_API
SQLAllocEnv(SQLHENV *OutputHandlePtr)
{
#ifdef ODBCDEBUG
    ODBCLOG("SQLAllocEnv\n");
#endif

    /* use mapping as described in ODBC 3 SDK Help file */
    return SQLAllocHandle_(SQL_HANDLE_ENV, SQL_NULL_HANDLE,
                           (SQLHANDLE *) OutputHandlePtr);
}
Exemple #26
0
static SQLRETURN
MNDBAllocEnv(SQLHANDLE *OutputHandlePtr)
{
	if (OutputHandlePtr == NULL) {
		return SQL_INVALID_HANDLE;
	}
	*OutputHandlePtr = (SQLHANDLE *) newODBCEnv();
#ifdef ODBCDEBUG
	ODBCLOG("new env %p\n", *OutputHandlePtr);
#endif
	return *OutputHandlePtr == NULL ? SQL_ERROR : SQL_SUCCESS;
}
Exemple #27
0
SQLRETURN SQL_API
SQLGetStmtOption(SQLHSTMT StatementHandle,
		 SQLUSMALLINT Option,
		 SQLPOINTER ValuePtr)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
	SQLULEN v;
	SQLRETURN r;

#ifdef ODBCDEBUG
	ODBCLOG("SQLGetStmtOption " PTRFMT " %s " PTRFMT "\n",
		PTRFMTCAST StatementHandle, translateStmtOption(Option),
		PTRFMTCAST ValuePtr);
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	/* only the ODBC 1.0 and ODBC 2.0 options */
	switch (Option) {
	case SQL_ASYNC_ENABLE:
	case SQL_CONCURRENCY:
	case SQL_CURSOR_TYPE:
	case SQL_NOSCAN:
	case SQL_QUERY_TIMEOUT:
	case SQL_RETRIEVE_DATA:
	case SQL_SIMULATE_CURSOR:
	case SQL_USE_BOOKMARKS:
	case SQL_ROW_NUMBER:
		/* SQLGetStmtAttr returns 64 bit value, but we need to
		 * return 32 bit value */
		r = MNDBGetStmtAttr(stmt, Option, &v, 0, NULL);
		if (SQL_SUCCEEDED(r))
			WriteData(ValuePtr, (SQLUINTEGER) v, SQLUINTEGER);
		return r;
	case SQL_BIND_TYPE:
	case SQL_KEYSET_SIZE:
	case SQL_MAX_LENGTH:
	case SQL_MAX_ROWS:
	case SQL_ROWSET_SIZE:
/*		case SQL_GET_BOOKMARKS:	is deprecated in ODBC 3.0+ */
		/* use mapping as described in ODBC 3.0 SDK Help */
		return MNDBGetStmtAttr(stmt, Option, ValuePtr, 0, NULL);
	default:
		/* Invalid attribute/option identifier */
		addStmtError(stmt, "HY092", NULL, 0);
		break;
	}

	return SQL_ERROR;
}
Exemple #28
0
SQLRETURN SQL_API
SQLFreeHandle(SQLSMALLINT HandleType,
	      SQLHANDLE Handle)
{
#ifdef ODBCDEBUG
	ODBCLOG("SQLFreeHandle %s " PTRFMT "\n",
		HandleType == SQL_HANDLE_ENV ? "Env" : HandleType == SQL_HANDLE_DBC ? "Dbc" : HandleType == SQL_HANDLE_STMT ? "Stmt" : "Desc",
		PTRFMTCAST Handle);
#endif

	return MNDBFreeHandle(HandleType, Handle);
}
Exemple #29
0
SQLRETURN SQL_API
SQLSetDescRec(SQLHDESC DescriptorHandle,
	      SQLSMALLINT RecNumber,
	      SQLSMALLINT Type,
	      SQLSMALLINT SubType,
	      SQLLEN Length,
	      SQLSMALLINT Precision,
	      SQLSMALLINT Scale,
	      SQLPOINTER DataPtr,
	      SQLLEN *StringLengthPtr,
	      SQLLEN *IndicatorPtr)
{
	ODBCDesc *desc = (ODBCDesc *) DescriptorHandle;

#ifdef ODBCDEBUG
	ODBCLOG("SQLSetDescRec " PTRFMT " %d %s %s " LENFMT " %d %d\n",
		PTRFMTCAST DescriptorHandle, (int) RecNumber,
		isAD(desc) ? translateCType(Type) : translateSQLType(Type),
		translateSubType(Type, SubType), LENCAST Length,
		(int) Precision, (int) Scale);
#endif

	if (!isValidDesc(desc))
		return SQL_INVALID_HANDLE;

	if (SQLSetDescField_(desc, RecNumber, SQL_DESC_TYPE,
			     (SQLPOINTER) (ssize_t) Type, 0) == SQL_ERROR)
		return SQL_ERROR;
	if ((Type == SQL_DATETIME || Type == SQL_INTERVAL) &&
	    SQLSetDescField_(desc, RecNumber, SQL_DESC_DATETIME_INTERVAL_CODE,
			     (SQLPOINTER) (ssize_t) SubType, 0) == SQL_ERROR)
		return SQL_ERROR;
	if (SQLSetDescField_(desc, RecNumber, SQL_DESC_OCTET_LENGTH,
			     (SQLPOINTER) (ssize_t) Length, 0) == SQL_ERROR)
		return SQL_ERROR;
	if (SQLSetDescField_(desc, RecNumber, SQL_DESC_PRECISION,
			     (SQLPOINTER) (ssize_t) Precision, 0) == SQL_ERROR)
		return SQL_ERROR;
	if (SQLSetDescField_(desc, RecNumber, SQL_DESC_SCALE,
			     (SQLPOINTER) (ssize_t) Scale, 0) == SQL_ERROR)
		return SQL_ERROR;
	if (SQLSetDescField_(desc, RecNumber, SQL_DESC_OCTET_LENGTH_PTR,
			     (SQLPOINTER) StringLengthPtr, 0) == SQL_ERROR)
		return SQL_ERROR;
	if (SQLSetDescField_(desc, RecNumber, SQL_DESC_INDICATOR_PTR,
			     (SQLPOINTER) IndicatorPtr, 0) == SQL_ERROR)
		return SQL_ERROR;
	if (SQLSetDescField_(desc, RecNumber, SQL_DESC_DATA_PTR,
			     (SQLPOINTER) DataPtr, 0) == SQL_ERROR)
		return SQL_ERROR;
	return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
}
Exemple #30
0
SQLRETURN SQL_API
SQLSpecialColumnsW(SQLHSTMT StatementHandle,
		   SQLUSMALLINT IdentifierType,
		   SQLWCHAR *CatalogName,
		   SQLSMALLINT NameLength1,
		   SQLWCHAR *SchemaName,
		   SQLSMALLINT NameLength2,
		   SQLWCHAR *TableName,
		   SQLSMALLINT NameLength3,
		   SQLUSMALLINT Scope,
		   SQLUSMALLINT Nullable)
{
	ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
	SQLRETURN rc = SQL_ERROR;
	SQLCHAR *catalog = NULL, *schema = NULL, *table = NULL;

#ifdef ODBCDEBUG
	ODBCLOG("SQLSpecialColumnsW %p %s ",
		StatementHandle,
		translateIdentifierType(IdentifierType));
#endif

	if (!isValidStmt(stmt))
		 return SQL_INVALID_HANDLE;

	clearStmtErrors(stmt);

	fixWcharIn(CatalogName, NameLength1, SQLCHAR, catalog,
		   addStmtError, stmt, goto bailout);
	fixWcharIn(SchemaName, NameLength2, SQLCHAR, schema,
		   addStmtError, stmt, goto bailout);
	fixWcharIn(TableName, NameLength3, SQLCHAR, table,
		   addStmtError, stmt, goto bailout);

	rc = MNDBSpecialColumns(stmt,
				IdentifierType,
				catalog, SQL_NTS,
				schema, SQL_NTS,
				table, SQL_NTS,
				Scope,
				Nullable);

      bailout:
	if (catalog)
		free(catalog);
	if (schema)
		free(schema);
	if (table)
		free(table);

	return rc;
}