Permalink
Browse files

Return the SQL Server data type and UDT classname in the metadata

Added a new field to the metadata, sqlType, that returns the datatype
as given by SQL Server (e.g., "varchar", "bigint", etc.)

When this type is "udt", an additional field, "udtType" is added that
contains the class name for the UDT type.  This can be used to see if
the type is a spatial type (e.g. "geography").

Also contain minor whitespace corrections (tabs to spaces).

Tests were updated to reflect the change.
  • Loading branch information...
jkint committed Feb 27, 2013
1 parent ce48c6d commit 2ac58c8dda77406f081db693c70f2986b29b6025
Showing with 226 additions and 124 deletions.
  1. +18 −1 src/OdbcConnection.cpp
  2. +4 −0 src/ResultSet.cpp
  3. +7 −5 src/ResultSet.h
  4. +18 −14 test/compoundqueries.js
  5. +74 −58 test/datatypes.js
  6. +1 −1 test/dates.js
  7. +14 −14 test/params.js
  8. +82 −23 test/query.js
  9. +8 −8 test/txn.js
View
@@ -109,9 +109,24 @@ namespace mssql
vector<wchar_t> buffer(nameLength+1);
ret = SQLDescribeCol(statement, column + 1, buffer.data(), nameLength+1, &nameLength, &current.dataType, &current.columnSize, &current.decimalDigits, &current.nullable);
CHECK_ODBC_ERROR( ret, statement );
-
current.name = wstring(buffer.data(), nameLength);
+ wchar_t typeName[1024];
+ SQLSMALLINT typeNameLen;
+ ret = SQLColAttribute( statement, column + 1, SQL_DESC_TYPE_NAME, typeName, 1024*sizeof(wchar_t),
+ &typeNameLen, NULL );
+ CHECK_ODBC_ERROR( ret, statement );
+ current.dataTypeName = wstring( typeName, typeNameLen );
+
+ if( current.dataType == SQL_SS_UDT ) {
+ wchar_t udtTypeName[1024];
+ SQLSMALLINT udtTypeNameLen;
+ ret = SQLColAttribute( statement, column + 1, SQL_CA_SS_UDT_TYPE_NAME, udtTypeName, 1024*sizeof(wchar_t),
+ &udtTypeNameLen, NULL );
+ CHECK_ODBC_ERROR( ret, statement );
+ current.udtTypeName = wstring(udtTypeName, udtTypeNameLen );
+ }
+
column++;
}
@@ -288,6 +303,8 @@ namespace mssql
case SQL_BINARY:
case SQL_VARBINARY:
case SQL_LONGVARBINARY:
+ case SQL_SS_UDT:
+
{
bool more = false;
vector<char> buffer(2048);
View
@@ -81,6 +81,10 @@ namespace mssql
entry->Set(New(L"size"), Integer::New(definition.columnSize));
entry->Set(New(L"nullable"), Boolean::New(definition.nullable != 0));
entry->Set(New(L"type"), New(typeName));
+ entry->Set(New(L"sqlType"), New(definition.dataTypeName.c_str()));
+ if( definition.dataType == SQL_SS_UDT ) {
+ entry->Set(New(L"udtType"), New(definition.udtTypeName.c_str()));
+ }
metadata->Set(metadata->Length(), entry);
});
View
@@ -35,13 +35,15 @@ namespace mssql
wstring name;
SQLULEN columnSize;
SQLSMALLINT dataType;
+ wstring dataTypeName;
SQLSMALLINT decimalDigits;
SQLSMALLINT nullable;
+ wstring udtTypeName;
};
ResultSet(int columns)
: rowcount(0),
- endOfRows(true)
+ endOfRows(true)
{
metadata.resize(columns);
column.reset();
@@ -74,18 +76,18 @@ namespace mssql
return rowcount;
}
- bool EndOfRows() const
+ bool EndOfRows() const
{
- return endOfRows;
+ return endOfRows;
}
private:
vector<ColumnDefinition> metadata;
SQLLEN rowcount;
- bool endOfRows;
+ bool endOfRows;
shared_ptr<Column> column;
- friend class OdbcConnection; // allow access to the endOfRows flag to just the ResultSet creating class
+ friend class OdbcConnection; // allow access to the endOfRows flag to just the ResultSet creating class
};
}
View
@@ -51,6 +51,7 @@ suite('compoundqueries', function () {
var testcolumnsize = 100;
var testcolumntype = " varchar(" + testcolumnsize + ")";
var testcolumnclienttype = "text";
+ var testcolumnsqltype = "varchar";
var testcolumnname = "col2";
var testdata1 = null;
var testdata2Expected = "string data row 2";
@@ -59,8 +60,8 @@ suite('compoundqueries', function () {
var expected1 = {
meta:
- [{ name: 'id', size: 10, nullable: false, type: 'number' },
- { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype}],
+ [{ name: 'id', size: 10, nullable: false, type: 'number', sqlType: 'int identity' },
+ { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype, sqlType: testcolumnsqltype }],
rows:
[[1, null],
[2, testdata2Expected]]
@@ -75,8 +76,8 @@ suite('compoundqueries', function () {
var expected3 = {
meta:
- [{ name: 'id', size: 10, nullable: false, type: 'number' },
- { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype}],
+ [{ name: 'id', size: 10, nullable: false, type: 'number', sqlType: 'int identity' },
+ { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype, sqlType: testcolumnsqltype }],
rows:
[[1, null],
[2, testdata2Expected],
@@ -105,6 +106,7 @@ suite('compoundqueries', function () {
var testcolumnsize = 100;
var testcolumntype = " varchar(" + testcolumnsize + ")";
var testcolumnclienttype = "text";
+ var testcolumnsqltype = "varchar";
var testcolumnname = "col2";
var testdata1 = null;
var testdata2Expected = "string data row 2";
@@ -113,8 +115,8 @@ suite('compoundqueries', function () {
var expected1 = {
meta:
- [{ name: 'id', size: 10, nullable: false, type: 'number' },
- { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype}],
+ [{ name: 'id', size: 10, nullable: false, type: 'number', sqlType: 'int identity' },
+ { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype, sqlType: testcolumnsqltype }],
rows:
[[1, null],
[2, testdata2Expected]]
@@ -149,6 +151,7 @@ suite('compoundqueries', function () {
var testcolumnsize = 100;
var testcolumntype = " varchar(" + testcolumnsize + ")";
var testcolumnclienttype = "text";
+ var testcolumnsqltype = "varchar";
var testcolumnname = "col2";
var testdata1 = null;
var testdata2Expected = "string data row 2";
@@ -157,17 +160,17 @@ suite('compoundqueries', function () {
var expected1 = {
meta:
- [{ name: 'id', size: 10, nullable: false, type: 'number' },
- { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype}],
+ [{ name: 'id', size: 10, nullable: false, type: 'number', sqlType: 'int identity' },
+ { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype, sqlType: testcolumnsqltype }],
rows:
[[1, null],
[2, testdata2Expected]]
};
var expected2 = {
meta:
- [{ name: 'id', size: 10, nullable: false, type: 'number' },
- { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype}],
+ [{ name: 'id', size: 10, nullable: false, type: 'number', sqlType: 'int identity' },
+ { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype, sqlType: testcolumnsqltype }],
rows:
[]
};
@@ -195,6 +198,7 @@ suite('compoundqueries', function () {
var testcolumnsize = 100;
var testcolumntype = " varchar(" + testcolumnsize + ")";
var testcolumnclienttype = "text";
+ var testcolumnsqltype = "varchar";
var testcolumnname = "col2";
var testdata1 = null;
var testdata2Expected = "string data row 2";
@@ -203,17 +207,17 @@ suite('compoundqueries', function () {
var expected1 = {
meta:
- [{ name: 'id', size: 10, nullable: false, type: 'number' },
- { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype}],
+ [{ name: 'id', size: 10, nullable: false, type: 'number', sqlType: 'int identity' },
+ { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype, sqlType: testcolumnsqltype }],
rows:
[[1, null],
[2, testdata2Expected]]
};
var expected2 = {
meta:
- [{ name: 'id', size: 10, nullable: false, type: 'number' },
- { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype}],
+ [{ name: 'id', size: 10, nullable: false, type: 'number', sqlType: 'int identity' },
+ { name: testcolumnname, size: testcolumnsize, nullable: true, type: testcolumnclienttype, sqlType: testcolumnsqltype }],
rows:
[]
};
Oops, something went wrong.

0 comments on commit 2ac58c8

Please sign in to comment.