Esempio n. 1
0
static void
DoTest(int n)
{
	SQLCHAR output[256];

	SQLSMALLINT colType;
	SQLULEN colSize;
	SQLSMALLINT colScale, colNullable;
	SQLLEN dataSize;

	TIMESTAMP_STRUCT ts;

	odbc_command("select convert(datetime, '2002-12-27 18:43:21')");

	CHKFetch("SI");
	CHKDescribeCol(1, (SQLTCHAR*)output, sizeof(output)/sizeof(SQLWCHAR), NULL, &colType, &colSize, &colScale, &colNullable, "S");

	if (n == 0) {
		memset(&ts, 0, sizeof(ts));
		CHKGetData(1, SQL_C_TIMESTAMP, &ts, sizeof(ts), &dataSize, "S");
		sprintf((char *) output, "%04d-%02d-%02d %02d:%02d:%02d.000", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
	} else {
		CHKGetData(1, SQL_C_CHAR, output, sizeof(output), &dataSize, "S");
	}

	printf("Date returned: %s\n", output);
	if (strcmp((char *) output, "2002-12-27 18:43:21.000") != 0) {
		fprintf(stderr, "Invalid returned date\n");
		exit(1);
	}

	CHKFetch("No");
	CHKCloseCursor("SI");
}
Esempio n. 2
0
static void
TestName(int index, const char *expected_name)
{
	char name[128];
	char buf[256];
	SQLSMALLINT len, type;

#define NAME_TEST \
	do { \
		if (strcmp(name, expected_name) != 0) \
		{ \
			sprintf(buf, "wrong name in column %d expected '%s' got '%s'", index, expected_name, name); \
			ODBC_REPORT_ERROR(buf); \
		} \
	} while(0)

	/* retrieve with SQLDescribeCol */
	CHKDescribeCol(index, (SQLCHAR *) name, sizeof(name), &len, &type, NULL, NULL, NULL, "S");
	NAME_TEST;

	/* retrieve with SQLColAttribute */
	CHKColAttribute(index, SQL_DESC_NAME, name, sizeof(name), &len, NULL, "S");
	if (odbc_db_is_microsoft())
		NAME_TEST;
	CHKColAttribute(index, SQL_DESC_LABEL, name, sizeof(name), &len, NULL, "S");
	NAME_TEST;
}
Esempio n. 3
0
static void
check_attr_ird(ATTR_PARAMS)
{
    SQLLEN i;
    SQLRETURN ret;

    if (attr->type == type_CHARP) {
        char buf[128];
        SQLSMALLINT len;

        ret = SQLColAttribute(odbc_stmt, 1, attr->value, buf, sizeof(buf), &len, NULL);
        if (!SQL_SUCCEEDED(ret))
            fatal("Line %u: failure not expected\n", line_num);
        buf[sizeof(buf)-1] = 0;
        if (strcmp(buf, expected_value) != 0) {
            g_result = 1;
            fprintf(stderr, "Line %u: invalid %s got %s expected %s\n", line_num, attr->name, buf, expected_value);
        }
        return;
    }

    i = 0xdeadbeef;
    ret = SQLColAttribute(odbc_stmt, 1, attr->value, NULL, SQL_IS_INTEGER, NULL, &i);
    if (!SQL_SUCCEEDED(ret))
        fatal("Line %u: failure not expected\n", line_num);
    /* SQL_DESC_LENGTH is the same of SQLDescribeCol len */
    if (attr->value == SQL_DESC_LENGTH) {
        SQLSMALLINT si;
        SQLULEN li;
        CHKDescribeCol(1, NULL, 0, NULL, &si, &li, &si, &si, "S");
        if (i != li)
            fatal("Line %u: attr %s SQLDescribeCol len %ld != SQLColAttribute len %ld\n", line_num, attr->name, (long) li, (long) i);
    }
    if (i != lookup(expected_value, attr->lookup)) {
        g_result = 1;
        fprintf(stderr, "Line %u: invalid %s got %ld expected %s\n", line_num, attr->name, (long int) i, expected_value);
    }
}
Esempio n. 4
0
int
main(int argc, char *argv[])
{
	SQLSMALLINT len, type;
	SQLTCHAR name[128];

	odbc_connect();
	odbc_command("create table #dc (col_name int, name2 varchar(100))");

	odbc_command("select * from #dc");

	len = 0x1234;
	CHKDescribeCol(1, NULL, 0, &len, &type, NULL, NULL, NULL, "S");
	check(len == 8);

	len = 0x1234;
	CHKDescribeCol(2, name, 0, &len, &type, NULL, NULL, NULL, "I");
	check(len == 5);

	len = 0x1234;
	CHKDescribeCol(1, NULL, 2, &len, &type, NULL, NULL, NULL, "S");
	check(len == 8);

	len = 0x1234;
	strcpy((char *) name, "xxx");
	CHKDescribeCol(2, name, 3, &len, &type, NULL, NULL, NULL, "I");
	check(len == 5 && strcmp(C(name), "na") == 0);

	len = 0x1234;
	strcpy((char *) name, "xxx");
	CHKDescribeCol(1, name, 1, &len, &type, NULL, NULL, NULL, "I");
	check(len == 8 && strcmp(C(name), "") == 0);

	len = 0x1234;
	strcpy((char *) name, "xxx");
	CHKDescribeCol(2, name, 6, &len, &type, NULL, NULL, NULL, "S");
	check(len == 5 && strcmp(C(name), "name2") == 0);

	odbc_disconnect();

	if (g_result == 0)
		printf("Done.\n");
	return g_result;
}
Esempio n. 5
0
/* Detect protocol version using queries
 * This to make possible protocol discovery on drivers like MS
 */
static int
odbc_tds_version_long(void)
{
	SQLRETURN ret;
	SQLSMALLINT scale, nullable, type;
	SQLULEN prec;
	ODBC_BUF *odbc_buf = NULL;

	/* statement must be in a consistent state to do the check */
	CHKExecDirect(T("select 1"), SQL_NTS, "S");
	odbc_reset_statement();

	/* select cast(123 as sql_variant) -> nvarchar('123') is 7.0 failure query is 5.0 ?? */
	ret = CHKExecDirect(T("select cast('123' as sql_variant)"), SQL_NTS, "SNoE");
	odbc_reset_statement();
	if (ret == SQL_ERROR) {
		ODBC_FREE();
		return 0x500;
	}

	/* see how bigint is returned, numeric means 7.0 */
	CHKExecDirect(T("select cast('123' as bigint)"), SQL_NTS, "S");
	CHKDescribeCol(1, NULL, 0, NULL, &type, &prec, &scale, &nullable, "S");
	odbc_reset_statement();
	if (type == SQL_NUMERIC || type == SQL_DECIMAL) {
		ODBC_FREE();
		return 0x700;
	}
	if (type != SQL_BIGINT) {
		fprintf(stderr, "Strange type returned trying to detect protocol version\n");
		odbc_disconnect();
		ODBC_FREE();
		exit(1);
	}

	/* select cast('123' as varchar(max)) -> ??? SQL_VARCHAR is 7.2 ?? */
	ret = CHKExecDirect(T("select cast('123' as varchar(max))"), SQL_NTS, "SE");
	if (ret == SQL_ERROR) {
		odbc_reset_statement();
		ODBC_FREE();
		return 0x701;
	}
	CHKDescribeCol(1, NULL, 0, NULL, &type, &prec, &scale, &nullable, "S");
	odbc_reset_statement();
	if (type == SQL_LONGVARCHAR) {
		ODBC_FREE();
		return 0x701;
	}
	if (type != SQL_VARCHAR) {
		fprintf(stderr, "Strange type returned trying to detect protocol version\n");
		odbc_disconnect();
		ODBC_FREE();
		exit(1);
	}

	/* select cast('12:13:14.1234' as time(4)) -> NVARCHAR('12:13:14.1234') is 7.2 else 7.3 */
	ret = CHKExecDirect(T("select cast('12:13:14.1234' as time(4))"), SQL_NTS, "SE");
	if (ret == SQL_ERROR) {
		odbc_reset_statement();
		ODBC_FREE();
		return 0x702;
	}
	CHKDescribeCol(1, NULL, 0, NULL, &type, &prec, &scale, &nullable, "S");
	odbc_reset_statement();
	if (scale == 4)
		return 0x703;
	if (scale != 0 || type != SQL_WVARCHAR) {
		fprintf(stderr, "Strange type or scale returned trying to detect protocol version\n");
		odbc_disconnect();
		ODBC_FREE();
		exit(1);
	}

	ODBC_FREE();
	return 0x702;
}