Skip to content

Commit c8ca7d7

Browse files
committedMar 27, 2012
Merge branch 'master' of github.com:qgis/Quantum-GIS
2 parents eef6f53 + 04e8268 commit c8ca7d7

File tree

2 files changed

+54
-58
lines changed

2 files changed

+54
-58
lines changed
 

‎src/providers/mssql/qgsmssqlprovider.cpp

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@
4848
#include "qgsmssqlsourceselect.h"
4949
#include "qgsmssqldataitems.h"
5050

51-
// grab sql constants
52-
#ifdef WIN32
53-
# include <windows.h>
54-
#endif
55-
#include <sqlext.h>
56-
5751
static const QString TEXT_PROVIDER_KEY = "mssql";
5852
static const QString TEXT_PROVIDER_DESCRIPTION = "MS SQL spatial data provider";
5953

@@ -232,60 +226,62 @@ QSqlDatabase QgsMssqlProvider::GetDatabase( QString driver, QString host, QStrin
232226
return db;
233227
}
234228

235-
QVariant::Type QgsMssqlProvider::DecodeODBCType( int sqltype )
229+
QVariant::Type QgsMssqlProvider::DecodeSqlType( QString sqlTypeName )
236230
{
237231
QVariant::Type type = QVariant::Invalid;
238-
switch ( sqltype )
232+
if ( sqlTypeName.startsWith( "decimal", Qt::CaseInsensitive ) ||
233+
sqlTypeName.startsWith( "numeric", Qt::CaseInsensitive ) ||
234+
sqlTypeName.startsWith( "real", Qt::CaseInsensitive ) ||
235+
sqlTypeName.startsWith( "float", Qt::CaseInsensitive ) )
239236
{
240-
case SQL_DECIMAL:
241-
case SQL_NUMERIC:
242-
case SQL_REAL:
243-
case SQL_FLOAT:
244-
case SQL_DOUBLE:
245-
type = QVariant::Double;
246-
break;
247-
case SQL_SMALLINT:
248-
case SQL_INTEGER:
249-
case SQL_BIT:
250-
case SQL_TINYINT:
251-
type = QVariant::Int;
252-
break;
253-
case SQL_BIGINT:
254-
type = QVariant::LongLong;
255-
break;
256-
case SQL_BINARY:
257-
case SQL_VARBINARY:
258-
case SQL_LONGVARBINARY:
259-
type = QVariant::ByteArray;
260-
break;
261-
case SQL_DATE:
262-
case SQL_TYPE_DATE:
263-
type = QVariant::Date;
264-
break;
265-
case SQL_TIME:
266-
case SQL_TYPE_TIME:
267-
type = QVariant::Time;
268-
break;
269-
case SQL_TIMESTAMP:
270-
case SQL_TYPE_TIMESTAMP:
271-
type = QVariant::DateTime;
272-
break;
273-
#ifndef Q_ODBC_VERSION_2
274-
case SQL_WCHAR:
275-
case SQL_WVARCHAR:
276-
case SQL_WLONGVARCHAR:
277-
type = QVariant::String;
278-
break;
279-
#endif
280-
case SQL_CHAR:
281-
case SQL_VARCHAR:
282-
case SQL_LONGVARCHAR:
283-
type = QVariant::String;
284-
break;
285-
default:
286-
type = QVariant::ByteArray;
287-
break;
237+
type = QVariant::Double;
238+
}
239+
else if ( sqlTypeName.startsWith( "char", Qt::CaseInsensitive ) ||
240+
sqlTypeName.startsWith( "nchar", Qt::CaseInsensitive ) ||
241+
sqlTypeName.startsWith( "varchar", Qt::CaseInsensitive ) ||
242+
sqlTypeName.startsWith( "nvarchar", Qt::CaseInsensitive ) ||
243+
sqlTypeName.startsWith( "text", Qt::CaseInsensitive ) ||
244+
sqlTypeName.startsWith( "ntext", Qt::CaseInsensitive ) )
245+
{
246+
type = QVariant::String;
288247
}
248+
else if ( sqlTypeName.startsWith( "smallint", Qt::CaseInsensitive ) ||
249+
sqlTypeName.startsWith( "int", Qt::CaseInsensitive ) ||
250+
sqlTypeName.startsWith( "bit", Qt::CaseInsensitive ) ||
251+
sqlTypeName.startsWith( "tinyint", Qt::CaseInsensitive ) )
252+
{
253+
type = QVariant::Int;
254+
}
255+
else if ( sqlTypeName.startsWith( "bigint", Qt::CaseInsensitive ) )
256+
{
257+
type = QVariant::LongLong;
258+
}
259+
else if ( sqlTypeName.startsWith( "binary", Qt::CaseInsensitive ) ||
260+
sqlTypeName.startsWith( "varbinary", Qt::CaseInsensitive ) ||
261+
sqlTypeName.startsWith( "image", Qt::CaseInsensitive ) )
262+
{
263+
type = QVariant::ByteArray;
264+
}
265+
else if ( sqlTypeName.startsWith( "date", Qt::CaseInsensitive ) )
266+
{
267+
type = QVariant::Date;
268+
}
269+
else if ( sqlTypeName.startsWith( "datetime", Qt::CaseInsensitive ) ||
270+
sqlTypeName.startsWith( "smalldatetime", Qt::CaseInsensitive ) ||
271+
sqlTypeName.startsWith( "datetime2", Qt::CaseInsensitive ) )
272+
{
273+
type = QVariant::DateTime;
274+
}
275+
else if ( sqlTypeName.startsWith( "time", Qt::CaseInsensitive ) ||
276+
sqlTypeName.startsWith( "timestamp", Qt::CaseInsensitive ) )
277+
{
278+
type = QVariant::Time;
279+
}
280+
else
281+
{
282+
QgsDebugMsg( QString( "Unknown field type: %1" ).arg( sqlTypeName ) );
283+
}
284+
289285
return type;
290286
}
291287

@@ -321,7 +317,7 @@ void QgsMssqlProvider::loadFields()
321317
while ( mQuery.next() )
322318
{
323319
QString sqlTypeName = mQuery.value( 5 ).toString();
324-
QVariant::Type sqlType = DecodeODBCType( mQuery.value( 4 ).toInt() );
320+
QVariant::Type sqlType = DecodeSqlType( sqlTypeName );
325321
if ( sqlTypeName == "geometry" || sqlTypeName == "geography" )
326322
{
327323
mGeometryColName = mQuery.value( 3 ).toString();

‎src/providers/mssql/qgsmssqlprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class QgsMssqlProvider : public QgsVectorDataProvider
283283

284284
protected:
285285
/** loads fields from input file to member attributeFields */
286-
QVariant::Type DecodeODBCType( int sqltype );
286+
QVariant::Type DecodeSqlType( QString sqlTypeName );
287287
void loadFields();
288288
void loadMetadata();
289289

0 commit comments

Comments
 (0)
Please sign in to comment.