SQLSetDescRec

It sets multiple descriptor fields to one record.

Syntax

SQLRETURN SQL_API SQLSetDescRec( SQLHDESC aDescriptorHandle,
SQLSMALLINT aRecordNumber,
SQLSMALLINT aType,
SQLSMALLINT aSubType,
SQLLEN aLength,
SQLSMALLINT aPrecision,
SQLSMALLINT aScale,
SQLPOINTER aData,
SQLLEN *aStringLength,
SQLLEN *aIndicator )

Arguments

Table. Arguments

Type Name of Argument Input/Output Description
SQLHDESC aDescriptorHandle Input Descriptor handle
SQLSMALLINT aRecordNumber Input Record number that contains the fields to be set: The starting value is 1.
SQLSMALLINT aType Input Type of descriptor
SQLSMALLINT aSubType Input Additional types: Set SQL_DATETIME and SQL_INTERVAL.
SQLLEN aLength Input Length of descriptor: Set SQL_DESC_OCTET_LENGTH.
SQLSMALLINT aPrecision Input Accuracy of descriptor: Set SQL_DESC_PRECISION.
SQLSMALLINT aScale Input If it the number of digits after the decimal point, SQL_DESC_SCALE is set.
SQLPOINTER aData Input or output Not used
SQLLEN aStringLength Input or output Pointer to length of descriptor: Set SQL_DESC_OCTET_LENGTH_PTR.
SQLLEN aIndicator Input or output • Set SQL_DESC_INDICATOR_PTR.

Return Values

Table. Return Values

|Return Value| Description| |SQL_SUCCESS|Normal termination| |SQL_ERROR|Abnormal termination • The record number that is out of range.| |SQL_INVALID_HANDLE | Abnormal termination • Invalid descriptor handle |

Diagnostic Codes

Table. Diagnostic Codes

Code Error Description
07009 Invalid descriptor index The record number is out of range.

SQLSetEnvAttr

It sets attributes that govern aspects of environments.

Syntax

SQLRETURN SQL_API SQLSetEnvAttr(SQLHENV aEnv,
SQLINTEGER aAttribute,
SQLPOINTER aValuePtr,
SQLINTEGER aValueLength)

Arguments

Table. Arguments

Type Name of Argument Input/Output Description
SQLHENV aEnv Input Environment handle
SQLINTEGER aAttribute Input Attribute handle
SQLPOINTER aValuePtr Input Input value
SQLINTEGER aValueLength Input Length of input value

Table of Attribute Value

Table. Table of Attribute Value

Attribute Description Data type
SQL_ATTR_ODBC_VERSION Versions of ODBC supported Integer
SQL_ATTR_OUTPUT_NTS Whether to use NTS Integer

Return Values

Table. Return Values

Return Value Description
SQL_SUCCESS Normal termination
SQL_ERROR Abnormal termination • Pointer to input values which is NULL • Invalid attribute value • Attribute values that are not supported • Feature not implemented
SQL_INVALID_HANDLE Abnormal termination • Invalid descriptor handle

Diagnostic Codes

Table. Diagnostic Codes

Code Error Description
HY009 Invalid use of null pointer Pointer to input value which is NULL.
HY024 Invalid attribute value Invalid attribute value
HY092 Invalid attribute/option identifier Attribute values that are not supported
HYC00 Optional feature not implemented Feature not implemented

SQLSetStmtAttr

It sets attributes related to a statement.

Syntax

SQLRETURN SQL_API SQLSetStmtAttr (SQLHSTMT aStmt,
SQLINTEGER aAttribute,
SQLPOINTER aValuePtr,
SQLINTEGER aValueLength)

Arguments

Table. Arguments

Type Name of Argument Input/Output Description
SQLHSTMT aStmt Input Statement handle
SQLINTEGER aAttribute Input Attribute handle
SQLPOINTER aValuePtr Input Pointer to input value
SQLINTEGER aValueLength Input Length of input value

Return Values

Table. Return Values

Return Value Description
SQL_SUCCESS Normal termination
SQL_SUCCESS_WITH_INFO Normal termination • The value of the option is changed.
SQL_ERROR Abnormal termination
SQL_INVALID_HANDLE Abnormal termination • Unallocated statement handle

Diagnostic Codes

Table. Diagnostic Codes

Code Error Description
01S02 Option value changed The value of the option is changed.
HY024 Invalid Attribute value Invalid input value
HYC00 Optional feature not implemented Attribute values that are not supported.

Sample Code

SQLSetStmtAttr(stmt, SQL_ATTR_MAX_ROWS, (SQLPOINTER)size, 0);

SQLStatistics

It retrieves a list of statistics about a single table and the indexes associated with the table.

Syntax

SQLRETURN SQL_API SQLStatistics(SQLHSTMT aStatementHandle,
SQLCHAR *aCatalogName,
SQLSMALLINT aNameLength1,
SQLCHAR *aSchemaName,
SQLSMALLINT aNameLength2,
SQLCHAR *aTableName,
SQLSMALLINT aNameLength3,
SQLUSMALLINT aUnique,
SQLUSMALLINT aReserved)

Arguments

Table. Arguments

Type Name of Argument Input/Output Description
SQLHSTMT aStatementHandle Input Statement handle
SQLCHAR* aCatalogName Input Not used
SQLSMALLINT aNameLength1 Input Not used
SQLCHAR* aSchemaName Input User name
SQLSMALLINT aNameLength2 Input Length of user name
SQLCHAR* aTableName Input Table Name
SQLSMALLINT aNameLength3 Input Length of table name
SQLUSMALLINT aUnique Input Not used
SQLUSMALLINT aReserved Input Not used

Return Values

Table. Return Values

Return Value Description
SQL_SUCCESS Normal termination
SQL_ERROR Abnormal termination. Table name was less than 0 but not equal to SQL_NTS.
SQL_INVALID_HANDLE Abnormal termination. Invalid statement handle

Diagnostic Codes

Table. Diagnostic Codes

Code Error Description
HY009 Invalid use of null pointer Table name was less tha 0 but not equal to SQL_NTS.

Sample Code

#include <stdio.h>
#include <stdlib.h>
#include <mach_sqlcli.h>
#include <string.h>

struct bindData//data binding Structure
{
SQLSMALLINT mTargetType;
char mTargetValuePtr[30];
SQLINTEGER mBufferMax;
SQLLEN mBufferLength;
};

void printError(SQLHENV aEnv, SQLHDBC aCon, SQLHSTMT aStmt, char* msg);//error Output function
void connectDB(SQLHENV* aEnv, SQLHDBC* aCon, SQLHSTMT* aStmt);//db Connection function
void disconnectDB(SQLHENV* aEnv, SQLHDBC* aCon, SQLHSTMT* aStmt);//db Disconnect function
void printResultTable(SQLHSTMT aStmt);//Results Table Output functions

int main()
{
SQLHENV sEnv = SQL_NULL_HANDLE;
SQLHDBC sCon = SQL_NULL_HANDLE;
SQLHSTMT sStmt = SQL_NULL_HANDLE;

char* sTableName = "apachetable";
char* sUserName = "SYS";

connectDB(&sEnv, &sCon, &sStmt);

if( SQLStatistics( sStmt, NULL, (SQLSMALLINT)0, (SQLCHAR*)sUserName, strlen(sUserName), (SQLCHAR*)sTableName, (SQLUSMALLINT)strlen(sTableName), 0, (SQLSMALLINT)0 ) == SQL_ERROR )
{
printError(sEnv, sCon, sStmt, "SQL Free Stmt Handle error");
}
printResultTable( sStmt );

disconnectDB(sEnv, sCon, sStmt);
return 0;
}

void printResultTable(SQLHSTMT aStmt)
{
struct bindData sBindData[50];
int sColumnCount = 0;
int i = 0;

if( SQLNumResultCols( aStmt, (SQLSMALLINT*)&sColumnCount ) == SQL_ERROR )
{
printError(NULL, NULL, aStmt, "SQL Num Result Columns error");
}

printf("Column Count : %d\n", sColumnCount);

for( i = 0 ; i < sColumnCount ; i++ )
{
sBindData[i].mTargetType = SQL_C_CHAR;
sBindData[i].mBufferMax = sizeof(sBindData[i].mTargetValuePtr);

if(SQLBindCol( aStmt, i+1,
sBindData[i].mTargetType,
(SQLPOINTER)sBindData[i].mTargetValuePtr,
sBindData[i].mBufferMax,
&sBindData[i].mBufferLength) == SQL_ERROR)
{
printError(NULL, NULL, aStmt, "SQL Bind Col error");
}
}

for( ; SQLFetch(aStmt) == SQL_SUCCESS ; )
{
for( i = 0; i < sColumnCount; i++ )
{
printf("%-20s'", sBindData[i].mTargetValuePtr);
}
printf("\n");
}
}

void connectDB(SQLHENV* aEnv, SQLHDBC* aCon, SQLHSTMT* aStmt)
{
char sConnStr[40] = "DSN=127.0.0.1;CONNTYPE=1;PORT_NO=9875";

if( SQLAllocEnv(aEnv) == SQL_ERROR )
{
printError(*aEnv, NULL, NULL, "SQL Alloc Env Handle error\n");
}

if( SQLAllocConnect(*aEnv, aCon) == SQL_ERROR )
{
printError(*aEnv, *aCon, NULL, "SQL Alloc Con Handle error\n");
}

if( SQLDriverConnect(*aCon, NULL,
(SQLCHAR*)sConnStr, SQL_NTS,
NULL, 0,
NULL, SQL_DRIVER_NOPROMPT) == SQL_ERROR )
{
printError(*aEnv, *aCon, NULL, "SQL Driver Connect error");
}

if( SQLAllocStmt(*aCon, aStmt) == SQL_ERROR )
{
printError(*aEnv, *aCon, *aStmt, "SQL Alloc Stmt Handle error");
}
}

void disconnectDB(SQLHENV* aEnv, SQLHDBC* aCon, SQLHSTMT* aStmt)
{
if( SQLFreeStmt( aStmt, SQL_DROP ) == SQL_ERROR )
{
printError(aEnv, aCon, aStmt, "SQL Free Stmt Handle error");
}

if( SQLDisconnect( aCon ) == SQL_ERROR )
{
printError(aEnv, aCon, NULL, "SQL Disconnect error");
}

if( SQLFreeConnect( aCon ) == SQL_ERROR )
{
printError(aEnv, aCon, NULL, "SQL Free Con Handle error");
}

if( SQLFreeEnv( aEnv ) == SQL_ERROR )
{
printError(aEnv, NULL, NULL, "SQL Free Env Handle error");
}
}

void printError(SQLHENV aEnv, SQLHDBC aCon, SQLHSTMT aStmt, char* msg)
{
SQLINTEGER sErrNo;
SQLSMALLINT sMsgLength;
SQLCHAR sErrMsg[1024];
SQLCHAR sSqlCode[6];

printf("%s\n", msg);
if( SQLError(aEnv, aCon, aStmt, sSqlCode, &sErrNo, sErrMsg, 1024, &sMsgLength) == SQL_SUCCESS )
{
printf("SQL[%s] Machbase[%d] - %s\n", sSqlCode, sErrNo, sErrMsg);
}
exit(-1);
}

SQLTables

It returns the list of table, catalog, or schema names, and table types, stored in a specific data source.

Syntax

SQLRETURN SQL_API SQLTables (SQLHSTMT aStmt,
SQLCHAR *aTableQualifier,
SQLSMALLINT aTableQualifierLength,
SQLCHAR *aTableOwner,
SQLSMALLINT aTableOwnerLength,
SQLCHAR *aTableName,
SQLSMALLINT aTableNameLength,
SQLCHAR *aTableType,
SQLSMALLINT aTableTypeLength)

Arguments

Table. Arguments

Type Name of Argument Input/Output Description
SQLHSTMT aStmt Input Statement handle
SQLCHAR* aTableQualifier Input Not used
SQLSMALLINT aTableQualifierLength Input Not used
SQLCHAR* aTableOwner Input Not used
SQLSMALLINT aTableOwnerLength Input Not used
SQLCHAR* aTableName Input Table Name
SQLSMALLINT aTableNameLength Input Length of table name
SQLCHAR* aTableType Input Not used
SQLSMALLINT aTableTypeLength Input Not used

Return Values

Table. Return Values

|Return Value | Description | | SQL_SUCCESS | Normal termination | | SQL_ERROR | Abnormal termination | | SQL_INVALID_HANDLE | Abnormal termination. Invalid statement handle

Sample Code

#include <stdio.h>
#include <stdlib.h>
#include <mach_sqlcli.h>

struct bindData//data binding Structure
{
SQLSMALLINT mTargetType;
char mTargetValuePtr[30];
SQLINTEGER mBufferMax;
SQLLEN mBufferLength;
};

void printError(SQLHENV aEnv, SQLHDBC aCon, SQLHSTMT aStmt, char* msg);//error Output function
void connectDB(SQLHENV* aEnv, SQLHDBC* aCon, SQLHSTMT* aStmt);//db Connection function
void disconnectDB(SQLHENV* aEnv, SQLHDBC* aCon, SQLHSTMT* aStmt);//db Disconnect function

int main()
{
SQLHENV sEnv = SQL_NULL_HANDLE;
SQLHDBC sCon = SQL_NULL_HANDLE;
SQLHSTMT sStmt = SQL_NULL_HANDLE;
struct bindData sBindData[5];
int i = 0;
int sColumnCount = 0;

connectDB(&sEnv, &sCon, &sStmt);

if( SQLTables( sStmt, NULL, (SQLSMALLINT)0, NULL, (SQLSMALLINT)0, NULL, (SQLSMALLINT)0, NULL, (SQLSMALLINT)0 ) == SQL_ERROR )
{
printError(sEnv, sCon, sStmt, "SQL Free Stmt Handle error");
}

if( SQLNumResultCols( sStmt, (SQLSMALLINT*)&sColumnCount ) == SQL_ERROR )
{
printError(sEnv, sCon, sStmt, "SQL Num Result Columns error");
}

printf("Column Count : %d\n", sColumnCount);

for( i = 0 ; i < sColumnCount ; i++ )
{
sBindData[i].mTargetType = SQL_C_CHAR;
sBindData[i].mBufferMax = sizeof(sBindData[i].mTargetValuePtr);

if(SQLBindCol( sStmt, i+1,
sBindData[i].mTargetType,
(SQLPOINTER)sBindData[i].mTargetValuePtr,
sBindData[i].mBufferMax,
&sBindData[i].mBufferLength) == SQL_ERROR)
{
printError(sEnv, sCon, sStmt, "SQL Bind Col error");
}
}

for( ; SQLFetch(sStmt) == SQL_SUCCESS ; )
{
for( i = 0; i < sColumnCount; i++ )
{
printf("%-20s'", sBindData[i].mTargetValuePtr);
}
printf("\n");
}

disconnectDB(sEnv, sCon, sStmt);
return 0;
}

void connectDB(SQLHENV* aEnv, SQLHDBC* aCon, SQLHSTMT* aStmt)
{
char sConnStr[40] = "DSN=127.0.0.1;CONNTYPE=1;PORT_NO=5656";

if( SQLAllocEnv(aEnv) == SQL_ERROR )
{
printError(*aEnv, NULL, NULL, "SQL Alloc Env Handle error\n");
}

if( SQLAllocConnect(*aEnv, aCon) == SQL_ERROR )
{
printError(*aEnv, *aCon, NULL, "SQL Alloc Con Handle error\n");
}

if( SQLDriverConnect(*aCon, NULL,
(SQLCHAR*)sConnStr, SQL_NTS,
NULL, 0,
NULL, SQL_DRIVER_NOPROMPT) == SQL_ERROR )
{
printError(*aEnv, *aCon, NULL, "SQL Driver Connect error");
}

if( SQLAllocStmt(*aCon, aStmt) == SQL_ERROR )
{
printError(*aEnv, *aCon, *aStmt, "SQL Alloc Stmt Handle error");
}
}

void disconnectDB(SQLHENV* aEnv, SQLHDBC* aCon, SQLHSTMT* aStmt)
{
if( SQLFreeStmt( aStmt, SQL_DROP ) == SQL_ERROR )
{
printError(aEnv, aCon, aStmt, "SQL Free Stmt Handle error");
}

if( SQLDisconnect( aCon ) == SQL_ERROR )
{
printError(aEnv, aCon, NULL, "SQL Disconnect error");
}

if( SQLFreeConnect( aCon ) == SQL_ERROR )
{
printError(aEnv, aCon, NULL, "SQL Free Con Handle error");
}

if( SQLFreeEnv( aEnv ) == SQL_ERROR )
{
printError(aEnv, NULL, NULL, "SQL Free Env Handle error");
}
}

void printError(SQLHENV aEnv, SQLHDBC aCon, SQLHSTMT aStmt, char* msg)
{
SQLINTEGER sErrNo;
SQLSMALLINT sMsgLength;
SQLCHAR sErrMsg[1024];
SQLCHAR sSqlCode[6];

printf("%s\n", msg);
if( SQLError(aEnv, aCon, aStmt, sSqlCode, &sErrNo, sErrMsg, 1024, &sMsgLength) == SQL_SUCCESS )
{
printf("SQL[%s] Machbase[%d] - %s\n", sSqlCode, sErrNo, sErrMsg);
}
exit(-1);
}

Unsupported Functions

Table. Unsupported Functions

Name of function Status
SQLBindParam Do not support
SQLBrowseConnect Do not support
SQLBulkOperations Do not support
SQLCloseCursor Replaced by SQLFreeStmt ()
SQLColAttributes Replaced by SQLFreeStmt ()
SQLColumnPrivileges Do not support
SQLDataSources Using internally
SQLDrivers Using internally
SQLEndTran Do not support
SQLExtendedFetch Do not support
SQLFetchScroll Do not support
SQLForeignKeys Do not support
SQLGetConnectOption Replaced by SQLGetConnectAttr
SQLGetCursorName Do not support
SQLGetStmtOption Replaced by SQLGetStmtAttr
SQLMoreResults Do not support
SQLParamData Do not support
SQLParamOptions Do not support
SQLPrimaryKeys Only internally using _arrival_time
SQLProcedureColumns Do not support
SQLProcedures Do not support
SQLPutData Do not support
SQLSetConnectOption Replaced by SQLSetConnectAttr
SQLSetCursorName Do not support
SQLSetParam Do not support
SQLSetPos Do not support
SQLSetScrollOptions Replaced by SQLSetInfo and SQLSetStmtAttr
SQLSetStmtOption Replaced by SQLSetStmtAttr
SQLSpecialColumns Do not support
SQLTablePrivileges Do not support
SQLTransact Do not support

results matching ""

    No results matching ""