Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSSQL provider: Remove the dependency from sqlext.h #105

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 53 additions & 57 deletions src/providers/mssql/qgsmssqlprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
#include "qgsmssqlsourceselect.h"
#include "qgsmssqldataitems.h"

// grab sql constants
#ifdef WIN32
# include <windows.h>
#endif
#include <sqlext.h>

static const QString TEXT_PROVIDER_KEY = "mssql";
static const QString TEXT_PROVIDER_DESCRIPTION = "MS SQL spatial data provider";

Expand Down Expand Up @@ -232,60 +226,62 @@ QSqlDatabase QgsMssqlProvider::GetDatabase( QString driver, QString host, QStrin
return db;
}

QVariant::Type QgsMssqlProvider::DecodeODBCType( int sqltype )
QVariant::Type QgsMssqlProvider::DecodeSqlType( QString sqlTypeName )
{
QVariant::Type type = QVariant::Invalid;
switch ( sqltype )
if (sqlTypeName.startsWith("decimal", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("numeric", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("real", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("float", Qt::CaseInsensitive))
{
case SQL_DECIMAL:
case SQL_NUMERIC:
case SQL_REAL:
case SQL_FLOAT:
case SQL_DOUBLE:
type = QVariant::Double;
break;
case SQL_SMALLINT:
case SQL_INTEGER:
case SQL_BIT:
case SQL_TINYINT:
type = QVariant::Int;
break;
case SQL_BIGINT:
type = QVariant::LongLong;
break;
case SQL_BINARY:
case SQL_VARBINARY:
case SQL_LONGVARBINARY:
type = QVariant::ByteArray;
break;
case SQL_DATE:
case SQL_TYPE_DATE:
type = QVariant::Date;
break;
case SQL_TIME:
case SQL_TYPE_TIME:
type = QVariant::Time;
break;
case SQL_TIMESTAMP:
case SQL_TYPE_TIMESTAMP:
type = QVariant::DateTime;
break;
#ifndef Q_ODBC_VERSION_2
case SQL_WCHAR:
case SQL_WVARCHAR:
case SQL_WLONGVARCHAR:
type = QVariant::String;
break;
#endif
case SQL_CHAR:
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
type = QVariant::String;
break;
default:
type = QVariant::ByteArray;
break;
type = QVariant::Double;
}
else if (sqlTypeName.startsWith("char", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("nchar", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("varchar", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("nvarchar", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("text", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("ntext", Qt::CaseInsensitive))
{
type = QVariant::String;
}
else if (sqlTypeName.startsWith("smallint", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("int", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("bit", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("tinyint", Qt::CaseInsensitive))
{
type = QVariant::Int;
}
else if (sqlTypeName.startsWith("bigint", Qt::CaseInsensitive))
{
type = QVariant::LongLong;
}
else if (sqlTypeName.startsWith("binary", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("varbinary", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("image", Qt::CaseInsensitive))
{
type = QVariant::ByteArray;
}
else if (sqlTypeName.startsWith("date", Qt::CaseInsensitive))
{
type = QVariant::Date;
}
else if (sqlTypeName.startsWith("datetime", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("smalldatetime", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("datetime2", Qt::CaseInsensitive))
{
type = QVariant::DateTime;
}
else if (sqlTypeName.startsWith("time", Qt::CaseInsensitive) ||
sqlTypeName.startsWith("timestamp", Qt::CaseInsensitive))
{
type = QVariant::Time;
}
else
{
QgsDebugMsg( QString("Unknown field type: %1").arg(sqlTypeName) );
}

return type;
}

Expand Down Expand Up @@ -321,7 +317,7 @@ void QgsMssqlProvider::loadFields()
while ( mQuery.next() )
{
QString sqlTypeName = mQuery.value( 5 ).toString();
QVariant::Type sqlType = DecodeODBCType( mQuery.value( 4 ).toInt() );
QVariant::Type sqlType = DecodeSqlType( sqlTypeName );
if ( sqlTypeName == "geometry" || sqlTypeName == "geography" )
{
mGeometryColName = mQuery.value( 3 ).toString();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mssql/qgsmssqlprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class QgsMssqlProvider : public QgsVectorDataProvider

protected:
/** loads fields from input file to member attributeFields */
QVariant::Type DecodeODBCType( int sqltype );
QVariant::Type DecodeSqlType( QString sqlTypeName );
void loadFields();
void loadMetadata();

Expand Down