info.c
上传用户:jmzj888
上传日期:2007-01-02
资源大小:220k
文件大小:25k
- /* Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
- This file is public domain and comes with NO WARRANTY of any kind */
- /*
- ** INFO.C - This is the ODBC sample driver code for
- ** exeting information functions.
- */
- #include "myodbc.h"
- #include <m_ctype.h>
- RETCODE SQL_API SQLGetInfo(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
- SWORD cbInfoValueMax, SWORD FAR *pcbInfoValue)
- {
- DBC FAR *dbc=(DBC FAR*) hdbc;
- char dummy2[16];
- SWORD dummy;
- DBUG_ENTER("SQLGetInfo");
- DBUG_PRINT("enter",("fInfoType: %d",fInfoType));
- if (!pcbInfoValue)
- pcbInfoValue=&dummy;
- if (!rgbInfoValue)
- { /* This is because of VB5 */
- rgbInfoValue=dummy2;
- cbInfoValueMax=sizeof(dummy2)-1;
- }
- switch (fInfoType) {
- case SQL_MAX_USER_NAME_LEN:
- #ifndef _UNIX_
- *(UNALIGNED SWORD FAR *) rgbInfoValue = 16;
- #endif /* IS NOT UNIX */
- #ifdef _UNIX_
- *(SWORD FAR *) rgbInfoValue = 16;
- #endif /* IS UNIX */
- break;
- case SQL_DRIVER_ODBC_VER:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,SQL_SPEC_STRING,
- cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_ACTIVE_CONNECTIONS:
- case SQL_ACTIVE_STATEMENTS:
- *((SWORD*) rgbInfoValue)=0; /* No limits */
- break;
- #ifdef SQL_ASYNC_MODE
- case SQL_ASYNC_MODE:
- *((SQLUINTEGER*) rgbInfoValue)= SQL_AM_NONE;
- break;
- #endif
- #ifdef SQL_CREATE_TABLE
- case SQL_CREATE_TABLE:
- *((SQLUINTEGER*) rgbInfoValue)= SQL_CT_CREATE_TABLE | SQL_CT_COLUMN_DEFAULT;
- break;
- #endif
- case SQL_DATA_SOURCE_NAME:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,dbc->dsn,
- cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_DATABASE_NAME:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,dbc->database,
- cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_DRIVER_NAME:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"myodbc.dll",
- cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_DRIVER_VER:
- case SQL_DBMS_VER:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,DRIVER_VERSION,
- cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_FETCH_DIRECTION:
- *((long*) rgbInfoValue)=SQL_FD_FETCH_NEXT | SQL_FD_FETCH_FIRST |
- SQL_FD_FETCH_LAST | SQL_FD_FETCH_PRIOR | SQL_FD_FETCH_ABSOLUTE |
- SQL_FD_FETCH_RELATIVE;
- if (dbc->flag & FLAG_NO_DEFAULT_CURSOR)
- *((long*) rgbInfoValue)&= ~ (long) SQL_FD_FETCH_PRIOR;
- if (dbc->flag & FLAG_NO_FETCH) /* For testing */
- *((long*) rgbInfoValue)= 0;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_ODBC_VER:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,DRIVER_VERSION,
- cbInfoValueMax)
- - (char*) rgbInfoValue);
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_ODBC_SAG_CLI_CONFORMANCE:
- *((SWORD*) rgbInfoValue)=SQL_OSCC_COMPLIANT;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_SERVER_NAME:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,dbc->mysql.host_info,
- cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_SEARCH_PATTERN_ESCAPE:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"\",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_ODBC_SQL_CONFORMANCE:
- case SQL_ODBC_API_CONFORMANCE:
- *((SWORD*) rgbInfoValue)=SQL_OAC_LEVEL1; /* Lie to make things work */
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_DBMS_NAME:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"MySQL",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_ROW_UPDATES:
- case SQL_ACCESSIBLE_PROCEDURES:
- case SQL_PROCEDURES:
- case SQL_EXPRESSIONS_IN_ORDERBY:
- case SQL_NEED_LONG_DATA_LEN:
- case SQL_DATA_SOURCE_READ_ONLY:
- case SQL_ODBC_SQL_OPT_IEF:
- case SQL_LIKE_ESCAPE_CLAUSE:
- case SQL_ORDER_BY_COLUMNS_IN_SELECT:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"N",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_OUTER_JOINS:
- if (dbc->mysql.protocol_version == MYSQL_3_21_PROTOCOL) /* MySQL 3.21 */
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,
- (dbc->flag & FLAG_OLD_ODBC_PROG) ? "Y" : "F",
- cbInfoValueMax)
- - (char*) rgbInfoValue);
- else
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"N",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- #ifdef SQL_OJ_CAPABILITIES
- case SQL_OJ_CAPABILITIES:
- *((SQLUINTEGER*) rgbInfoValue)= SQL_OJ_LEFT | SQL_OJ_NESTED | SQL_OJ_NOT_ORDERED |
- SQL_OJ_INNER | SQL_OJ_ALL_COMPARISON_OPS;
- *pcbInfoValue=sizeof(SQLUINTEGER);
- break;
- #endif
- case SQL_COLUMN_ALIAS:
- case SQL_ACCESSIBLE_TABLES:
- case SQL_MULT_RESULT_SETS:
- case SQL_MULTIPLE_ACTIVE_TXN:
- case SQL_MAX_ROW_SIZE_INCLUDES_LONG:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"Y",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- #ifdef SQL_MAX_IDENTIFIER_LEN
- case SQL_MAX_IDENTIFIER_LEN:
- *((SQLUSMALLINT*) rgbInfoValue)=NAME_LEN;
- break;
- #endif
- case SQL_CONCAT_NULL_BEHAVIOR:
- *((SWORD*) rgbInfoValue)=SQL_CB_NULL;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_CURSOR_COMMIT_BEHAVIOR: /* Lie */
- case SQL_CURSOR_ROLLBACK_BEHAVIOR:
- *((SWORD*) rgbInfoValue)=SQL_CB_PRESERVE;
- *pcbInfoValue=sizeof(SWORD);
- break;
- #ifdef SQL_CURSOR_SENSITIVITY
- case SQL_CURSOR_SENSITIVITY:
- *((SQLUINTEGER*) rgbInfoValue)=SQL_UNSPECIFIED;
- break
- #endif
- case SQL_DEFAULT_TXN_ISOLATION:
- *((long*) rgbInfoValue)= SQL_TXN_READ_UNCOMMITTED;
- *pcbInfoValue=sizeof(long);
- break;
- #ifdef SQL_DESCRIBE_PARAMETER
- case SQL_DESCRIBE_PARAMETER:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"N",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- #endif
- case SQL_TXN_ISOLATION_OPTION:
- *((long*) rgbInfoValue)= SQL_TXN_READ_UNCOMMITTED;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_IDENTIFIER_CASE:
- *((SWORD*) rgbInfoValue)=SQL_IC_MIXED;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_IDENTIFIER_QUOTE_CHAR:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue," ",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_MAX_COLUMN_NAME_LEN:
- *((SWORD*) rgbInfoValue)=NAME_LEN;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_MAX_CURSOR_NAME_LEN:
- case SQL_MAX_OWNER_NAME_LEN:
- case SQL_MAX_PROCEDURE_NAME_LEN:
- case SQL_MAX_QUALIFIER_NAME_LEN:
- *((SWORD*) rgbInfoValue)=0;
- break;
- case SQL_MAX_TABLE_NAME_LEN:
- *((SWORD*) rgbInfoValue)=NAME_LEN;
- break;
- case SQL_OWNER_TERM:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"owner",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_PROCEDURE_TERM:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"procedure",
- cbInfoValueMax) - (char*) rgbInfoValue);
- break;
- case SQL_QUALIFIER_NAME_SEPARATOR: /* what should this be */
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,",",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_QUALIFIER_TERM:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"database",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_SCROLL_CONCURRENCY:
- case SQL_SCROLL_OPTIONS:
- *((long*) rgbInfoValue)=0L;
- break;
- case SQL_TABLE_TERM:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"table",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_TXN_CAPABLE:
- *((SWORD*) rgbInfoValue)=SQL_TC_NONE;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_USER_NAME:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,"user",cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_CONVERT_FUNCTIONS:
- *((long*) rgbInfoValue)=0L;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_SYSTEM_FUNCTIONS:
- *((long*) rgbInfoValue)= SQL_FN_SYS_DBNAME | SQL_FN_SYS_IFNULL | SQL_FN_SYS_USERNAME;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_NUMERIC_FUNCTIONS:
- *((long*) rgbInfoValue)=SQL_FN_NUM_ABS | SQL_FN_NUM_ACOS |
- SQL_FN_NUM_ASIN | SQL_FN_NUM_ATAN | SQL_FN_NUM_ATAN2 |
- SQL_FN_NUM_CEILING | SQL_FN_NUM_COS | SQL_FN_NUM_COT | SQL_FN_NUM_EXP |
- SQL_FN_NUM_FLOOR | SQL_FN_NUM_LOG | SQL_FN_NUM_MOD | SQL_FN_NUM_SIGN |
- SQL_FN_NUM_SIN | SQL_FN_NUM_SQRT | SQL_FN_NUM_TAN | SQL_FN_NUM_PI |
- SQL_FN_NUM_RAND | SQL_FN_NUM_DEGREES | SQL_FN_NUM_LOG10 |
- SQL_FN_NUM_POWER | SQL_FN_NUM_RADIANS | SQL_FN_NUM_ROUND |
- SQL_FN_NUM_TRUNCATE;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_STRING_FUNCTIONS:
- *((long*) rgbInfoValue)=SQL_FN_STR_CONCAT | SQL_FN_STR_INSERT |
- SQL_FN_STR_LEFT | SQL_FN_STR_LTRIM | SQL_FN_STR_LENGTH |
- SQL_FN_STR_LOCATE | SQL_FN_STR_LCASE | SQL_FN_STR_REPEAT |
- SQL_FN_STR_REPLACE | SQL_FN_STR_RIGHT | SQL_FN_STR_RTRIM |
- SQL_FN_STR_SUBSTRING | SQL_FN_STR_UCASE | SQL_FN_STR_ASCII |
- SQL_FN_STR_CHAR | SQL_FN_STR_LOCATE_2 | SQL_FN_STR_SOUNDEX |
- SQL_FN_STR_SPACE;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_TIMEDATE_FUNCTIONS:
- *((long*) rgbInfoValue)= SQL_FN_TD_NOW | SQL_FN_TD_CURDATE |
- SQL_FN_TD_DAYOFMONTH | SQL_FN_TD_DAYOFWEEK | SQL_FN_TD_DAYOFYEAR |
- SQL_FN_TD_MONTH | SQL_FN_TD_QUARTER | SQL_FN_TD_WEEK | SQL_FN_TD_YEAR |
- SQL_FN_TD_CURTIME | SQL_FN_TD_HOUR | SQL_FN_TD_MINUTE |
- SQL_FN_TD_SECOND | SQL_FN_TD_DAYNAME | SQL_FN_TD_MONTHNAME;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_CONVERT_BIGINT:
- case SQL_CONVERT_BIT:
- case SQL_CONVERT_CHAR:
- case SQL_CONVERT_DATE:
- case SQL_CONVERT_DECIMAL:
- case SQL_CONVERT_DOUBLE:
- case SQL_CONVERT_FLOAT:
- case SQL_CONVERT_INTEGER:
- case SQL_CONVERT_LONGVARCHAR:
- case SQL_CONVERT_NUMERIC:
- case SQL_CONVERT_REAL:
- case SQL_CONVERT_SMALLINT:
- case SQL_CONVERT_TIME:
- case SQL_CONVERT_TIMESTAMP:
- case SQL_CONVERT_TINYINT:
- case SQL_CONVERT_VARCHAR:
- /* lie that we can handle anything */
- *((long*) rgbInfoValue)=SQL_CVT_CHAR | SQL_CVT_NUMERIC | SQL_CVT_DECIMAL |
- SQL_CVT_INTEGER | SQL_CVT_SMALLINT | SQL_CVT_FLOAT | SQL_CVT_REAL |
- SQL_CVT_DOUBLE | SQL_CVT_VARCHAR | SQL_CVT_LONGVARCHAR |
- SQL_CVT_BIT | SQL_CVT_TINYINT | SQL_CVT_BIGINT |
- SQL_CVT_DATE | SQL_CVT_TIME | SQL_CVT_TIMESTAMP;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_CONVERT_BINARY:
- case SQL_CONVERT_VARBINARY:
- case SQL_CONVERT_LONGVARBINARY:
- case SQL_POSITIONED_STATEMENTS:
- case SQL_LOCK_TYPES:
- case SQL_BOOKMARK_PERSISTENCE:
- case SQL_OWNER_USAGE:
- case SQL_QUALIFIER_USAGE:
- case SQL_SUBQUERIES:
- case SQL_UNION:
- case SQL_TIMEDATE_ADD_INTERVALS:
- case SQL_TIMEDATE_DIFF_INTERVALS:
- *((long*) rgbInfoValue)=0L;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_QUOTED_IDENTIFIER_CASE:
- *((SQLUSMALLINT*) rgbInfoValue)=SQL_IC_MIXED;
- break;
- case SQL_POS_OPERATIONS:
- *((long*) rgbInfoValue)=SQL_POS_POSITION;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_ALTER_TABLE:
- *((long*) rgbInfoValue)=SQL_AT_ADD_COLUMN | SQL_AT_DROP_COLUMN;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_CORRELATION_NAME:
- *((SWORD*) rgbInfoValue)=SQL_CN_DIFFERENT;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_NON_NULLABLE_COLUMNS:
- *((SWORD*) rgbInfoValue)=SQL_NNC_NON_NULL;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_NULL_COLLATION:
- *((SWORD*) rgbInfoValue)=SQL_NC_START;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_MAX_COLUMNS_IN_GROUP_BY:
- case SQL_MAX_COLUMNS_IN_ORDER_BY:
- case SQL_MAX_COLUMNS_IN_SELECT:
- case SQL_MAX_COLUMNS_IN_TABLE:
- case SQL_MAX_ROW_SIZE:
- *((SWORD*) rgbInfoValue)=0;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_MAX_TABLES_IN_SELECT:
- *((SWORD*) rgbInfoValue)=32;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_MAX_BINARY_LITERAL_LEN:
- case SQL_MAX_CHAR_LITERAL_LEN:
- *((long*) rgbInfoValue)=0;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_MAX_COLUMNS_IN_INDEX:
- *((SWORD*) rgbInfoValue)=16;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_MAX_INDEX_SIZE:
- *((long*) rgbInfoValue)=120;
- *pcbInfoValue=sizeof(long);
- break;
- #if (ODBCVER >= 0x0300)
- case SQL_MAX_IDENTIFIER_LENGTH:
- *((long*) rgbInfoValue)=NAME_LEN;
- *pcbInfoValue=sizeof(long);
- break;
- #endif
- case SQL_MAX_STATEMENT_LEN:
- *((long*) rgbInfoValue)=net_buffer_length;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_QUALIFIER_LOCATION:
- *((SWORD*) rgbInfoValue)=SQL_QL_START;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_GETDATA_EXTENSIONS:
- *((long*) rgbInfoValue)= SQL_GD_ANY_COLUMN | SQL_GD_ANY_ORDER | SQL_GD_BOUND;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_STATIC_SENSITIVITY:
- // *((long*) rgbInfoValue)=SQL_SS_DELETIONS | SQL_SS_UPDATES;
- *((long*) rgbInfoValue)=0;
- *pcbInfoValue=sizeof(long);
- break;
- case SQL_FILE_USAGE:
- *((SWORD*) rgbInfoValue)=SQL_FILE_NOT_SUPPORTED;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_GROUP_BY:
- *((SWORD*) rgbInfoValue)=SQL_GB_NO_RELATION;
- *pcbInfoValue=sizeof(SWORD);
- break;
- case SQL_KEYWORDS:
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,
- "UNIQUE,ZEROFILL,UNSIGNED,BIGINT,BLOB,TINYBLOB,MEDIMUMBLOB,LONGBLOB,MEDIUMINT,PROCEDURE,SHOW,LIMIT,DEFAULT,TABLES,REGEXP,RLIKE,KEYS,TINTTEXT,MEDIUMTEXT",
- cbInfoValueMax)
- - (char*) rgbInfoValue);
- break;
- case SQL_SPECIAL_CHARACTERS:
- {
- *pcbInfoValue=(SWORD) (strmake((char*) rgbInfoValue,
- "屈殁溧彗觌栾铎呐涉启鲵