Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix int/integer datatype confusion in primary key identification for …
…the sqlanywhere provider
  • Loading branch information
ddehaan committed Oct 28, 2012
1 parent 462d8a8 commit e0f9d53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/providers/sqlanywhere/qgssqlanywhereprovider.cpp
Expand Up @@ -557,7 +557,7 @@ QgsSqlAnywhereProvider::findKeyColumn()
"FROM SYSTABCOL "
"WHERE table_id = %1 "
"AND column_name = %2 "
"AND base_type_str IN ( 'int', 'unsigned int', 'smallint', 'unsigned smallint', 'tinyint' ) " )
"AND base_type_str IN ( 'int', 'integer', 'unsigned int', 'smallint', 'unsigned smallint', 'tinyint' ) " )
.arg( mTableId )
.arg( quotedValue( mKeyColumn ) );
stmt = mConnRO->execute_direct( sql );
Expand Down Expand Up @@ -630,7 +630,7 @@ QgsSqlAnywhereProvider::findKeyColumn()
"'SELECT * FROM %1', 1 ) dq1 "
"WHERE is_key_column = 1 "
"AND is_added_key_column = 0 "
"AND domain_name IN ( 'int', 'unsigned int', 'smallint', 'unsigned smallint', 'tinyint' ) "
"AND domain_name IN ( 'int', 'integer', 'unsigned int', 'smallint', 'unsigned smallint', 'tinyint' ) "
"AND NOT EXISTS ( "
"SELECT column_number "
"FROM sa_describe_query( "
Expand Down Expand Up @@ -662,7 +662,7 @@ QgsSqlAnywhereProvider::findKeyColumn()
"AND c.column_id = ic.column_id "
"WHERE i.table_id = %1 "
"AND i.\"unique\" IN ( 1, 2 ) "
"AND c.base_type_str IN ( 'int', 'unsigned int', 'smallint', 'unsigned smallint', 'tinyint' ) "
"AND c.base_type_str IN ( 'int', 'integer', 'unsigned int', 'smallint', 'unsigned smallint', 'tinyint' ) "
"AND NOT EXISTS ( "
"SELECT column_id "
"FROM SYSIDXCOL ic2 "
Expand All @@ -686,7 +686,7 @@ QgsSqlAnywhereProvider::findKeyColumn()
sql = QString( "SELECT column_name "
"FROM SYSTABCOL "
"WHERE table_id = %1 "
"AND base_type_str IN ( 'int', 'unsigned int', 'smallint', 'unsigned smallint', 'tinyint' ) " )
"AND base_type_str IN ( 'int', 'integer', 'unsigned int', 'smallint', 'unsigned smallint', 'tinyint' ) " )
.arg( mTableId );
stmt = mConnRO->execute_direct( sql );
while ( stmt->isValid() && stmt->fetchNext() )
Expand Down Expand Up @@ -1018,6 +1018,7 @@ QgsSqlAnywhereProvider::uniqueValues( int index, QList < QVariant > &uniqueValue
}
} // QgsSqlAnywhereProvider::uniqueValues()


QString
QgsSqlAnywhereProvider::getDefaultValue( QString attrName )
{
Expand Down Expand Up @@ -1582,6 +1583,10 @@ QgsSqlAnywhereProvider::changeGeometryValues( QgsGeometryMap & gmap )
return ok;
} // QgsSqlAnywhereProvider::changeGeometryValues()

QgsAttributeList QgsSqlAnywhereProvider::attributeIndexes()
{
return mAttributeFields.keys();
}

bool
QgsSqlAnywhereProvider::ensureConnRO()
Expand Down
12 changes: 12 additions & 0 deletions src/providers/sqlanywhere/qgssqlanywhereprovider.h
Expand Up @@ -152,10 +152,22 @@ class QgsSqlAnywhereProvider: public QgsVectorDataProvider
* @param limit maximum number of values (added in 1.4) */
virtual void uniqueValues( int index, QList < QVariant > &uniqueValues, int limit = -1 );

/** Returns the possible enum values of an attribute.
* Returns an empty stringlist if a provider does not support enum types
* or if the given attribute is not an enum type.
* @param index the index of the attribute
* @param enumList reference to the list to fill
* @note: added in version 1.2
* SQLAnywhere does not currently support enumerated types.
*/
//virtual void enumValues( int index, QStringList& enumList );

/**Returns true if layer is valid
*/
bool isValid() { return mValid; }

QgsAttributeList attributeIndexes();

/**Returns the default value for field specified by @c fieldId */
QVariant defaultValue( int fieldId ) { return mAttributeDefaults[fieldId]; }

Expand Down

0 comments on commit e0f9d53

Please sign in to comment.