Skip to content

Commit

Permalink
Merge pull request #448 from szekerest/master
Browse files Browse the repository at this point in the history
MSSQL Fixes (Fix #6733 and Fix #7254)
  • Loading branch information
NathanW2 committed Mar 5, 2013
2 parents 2f53505 + 6d1eb26 commit 3cf8840
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
40 changes: 23 additions & 17 deletions src/providers/mssql/qgsmssqlgeometryparser.cpp
Expand Up @@ -23,13 +23,13 @@
/* SqlGeometry serialization format
Simple Point (SerializationProps & IsSinglePoint)
[SRID][0x01][SerializationProps][Point]
[SRID][0x01][SerializationProps][Point][z][m]
Simple Line Segment (SerializationProps & IsSingleLineSegment)
[SRID][0x01][SerializationProps][Point][Point]
[SRID][0x01][SerializationProps][Point1][Point2][z1][z2][m1][m2]
Complex Geometries
[SRID][0x01][SerializationProps][NumPoints][Point]..[Point]
[SRID][0x01][SerializationProps][NumPoints][Point1]..[PointN][z1]..[zN][m1]..[mN]
[NumFigures][Figure]..[Figure][NumShapes][Shape]..[Shape]
SRID
Expand All @@ -44,8 +44,8 @@ SerializationProps (bitmask) 1 byte
0x20 = IsWholeGlobe
Point (2-4)x8 bytes, size depends on SerializationProps & HasZValues & HasMValues
[x][y][z][m] - SqlGeometry
[latitude][longitude][z][m] - SqlGeography
[x][y] - SqlGeometry
[latitude][longitude] - SqlGeography
Figure
[FigureAttribute][PointOffset]
Expand Down Expand Up @@ -107,9 +107,10 @@ ShapeType (1 byte)
#define PointOffset(iFigure) (ReadInt32(nFigurePos + (iFigure) * 5 + 1))
#define NextPointOffset(iFigure) (iFigure + 1 < nNumFigures? PointOffset((iFigure) +1) : nNumPoints)

#define ReadX(iPoint) (ReadDouble(nPointPos + nPointSize * (iPoint)))
#define ReadY(iPoint) (ReadDouble(nPointPos + nPointSize * (iPoint) + 8))
#define ReadZ(iPoint) (ReadDouble(nPointPos + nPointSize * (iPoint) + 16))
#define ReadX(iPoint) (ReadDouble(nPointPos + 16 * (iPoint)))
#define ReadY(iPoint) (ReadDouble(nPointPos + 16 * (iPoint) + 8))
#define ReadZ(iPoint) (ReadDouble(nPointPos + 16 * nNumPoints + 8 * (iPoint)))
#define ReadM(iPoint) (ReadDouble(nPointPos + 24 * nNumPoints + 8 * (iPoint)))

/************************************************************************/
/* QgsMssqlGeometryParser() */
Expand Down Expand Up @@ -175,16 +176,19 @@ void QgsMssqlGeometryParser::CopyBytes( void* src, int len )
/* CopyCoordinates() */
/************************************************************************/

void QgsMssqlGeometryParser::CopyCoordinates( unsigned char* src )
void QgsMssqlGeometryParser::CopyCoordinates( int iPoint )
{
if ( IsGeography )
{
CopyBytes( src + 8, 8 ); // longitude
CopyBytes( src, 8 ); // latitude
CopyBytes(pszData + nPointPos + 16 * iPoint + 8, 8); // longitude
CopyBytes(pszData + nPointPos + 16 * iPoint, 8); // latitude
}
else
// copy geometry coords
CopyBytes( src, nPointSize );
CopyBytes(pszData + nPointPos + 16 * iPoint, 16);

if ( chProps & SP_HASZVALUES )
CopyBytes(pszData + nPointPos + 16 * nNumPoints + 8 * iPoint, 8); // copy z value
}

/************************************************************************/
Expand All @@ -203,7 +207,7 @@ void QgsMssqlGeometryParser::CopyPoint( int iPoint )
wkbType = QGis::WKBPoint;
CopyBytes( &wkbType, 4 );
// copy coordinates
CopyCoordinates( pszData + nPointPos + nPointSize * iPoint );
CopyCoordinates( iPoint );
}

/************************************************************************/
Expand Down Expand Up @@ -284,7 +288,7 @@ void QgsMssqlGeometryParser::ReadLineString( int iShape )
i = 0;
while ( iPoint < iNextPoint )
{
CopyCoordinates( pszData + nPointPos + nPointSize * iPoint );
CopyCoordinates( iPoint );
++iPoint;
++i;
}
Expand Down Expand Up @@ -358,7 +362,7 @@ void QgsMssqlGeometryParser::ReadPolygon( int iShape )
i = 0;
while ( iPoint < iNextPoint )
{
CopyCoordinates( pszData + nPointPos + nPointSize * iPoint );
CopyCoordinates( iPoint );
++iPoint;
++i;
}
Expand Down Expand Up @@ -490,6 +494,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput
if ( chProps & SP_ISSINGLEPOINT )
{
// single point geometry
nNumPoints = 1;
nPointPos = 6;

if ( nLen < 6 + nPointSize )
Expand All @@ -505,6 +510,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput
else if ( chProps & SP_ISSINGLELINESEGMENT )
{
// single line segment with 2 points
nNumPoints = 2;
nPointPos = 6;

if ( nLen < 6 + 2 * nPointSize )
Expand All @@ -528,8 +534,8 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput
int iCount = 2;
CopyBytes( &iCount, 4 );
// copy points
CopyCoordinates( pszData + nPointPos );
CopyCoordinates( pszData + nPointPos + nPointSize );
CopyCoordinates( 0 );
CopyCoordinates( 1 );
}
else
{
Expand Down
18 changes: 18 additions & 0 deletions src/providers/mssql/qgsmssqlnewconnection.cpp
Expand Up @@ -49,6 +49,7 @@ QgsMssqlNewConnection::QgsMssqlNewConnection( QWidget *parent, const QString& co
{
txtUsername->setText( settings.value( key + "/username" ).toString() );
chkStoreUsername->setChecked( true );
cb_trustedConnection->setChecked (false);
}

if ( settings.value( key + "/savePassword" ).toString() == "true" )
Expand All @@ -71,6 +72,7 @@ QgsMssqlNewConnection::QgsMssqlNewConnection( QWidget *parent, const QString& co

txtName->setText( connName );
}
on_cb_trustedConnection_clicked();
}
/** Autoconnected SLOTS **/
void QgsMssqlNewConnection::accept()
Expand Down Expand Up @@ -127,6 +129,22 @@ void QgsMssqlNewConnection::on_btnConnect_clicked()
testConnection();
}

void QgsMssqlNewConnection::on_cb_trustedConnection_clicked()
{
if ( cb_trustedConnection->checkState() == Qt::Checked )
{
txtUsername->setEnabled( false );
txtUsername->setText( "" );
txtPassword->setEnabled( false );
txtPassword->setText( "" );
}
else
{
txtUsername->setEnabled( true );
txtPassword->setEnabled( true );
}
}

/** end Autoconnected SLOTS **/

QgsMssqlNewConnection::~QgsMssqlNewConnection()
Expand Down
1 change: 1 addition & 0 deletions src/providers/mssql/qgsmssqlnewconnection.h
Expand Up @@ -37,6 +37,7 @@ class QgsMssqlNewConnection : public QDialog, private Ui::QgsMssqlNewConnectionB
public slots:
void accept();
void on_btnConnect_clicked();
void on_cb_trustedConnection_clicked();
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
private:
QString mOriginalConnName; //store initial name to delete entry in case of rename
Expand Down
17 changes: 13 additions & 4 deletions src/providers/mssql/qgsmssqlprovider.cpp
Expand Up @@ -133,9 +133,6 @@ QgsMssqlProvider::QgsMssqlProvider( QString uri )
mWkbType = QGis::WKBNoGeometry;
mSRId = 0;
}

if ( mFidColName.isEmpty() )
mValid = false;
}

//fill type names into sets
Expand Down Expand Up @@ -947,6 +944,9 @@ bool QgsMssqlProvider::changeAttributeValues( const QgsChangedAttributesMap & at
if ( attr_map.isEmpty() )
return true;

if ( mFidColName.isEmpty() )
return false;

for ( QgsChangedAttributesMap::const_iterator it = attr_map.begin(); it != attr_map.end(); ++it )
{
QgsFeatureId fid = it.key();
Expand Down Expand Up @@ -1055,6 +1055,9 @@ bool QgsMssqlProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
if ( geometry_map.isEmpty() )
return true;

if ( mFidColName.isEmpty() )
return false;

for ( QgsGeometryMap::iterator it = geometry_map.begin(); it != geometry_map.end(); ++it )
{
QgsFeatureId fid = it.key();
Expand Down Expand Up @@ -1125,6 +1128,9 @@ bool QgsMssqlProvider::changeGeometryValues( QgsGeometryMap & geometry_map )

bool QgsMssqlProvider::deleteFeatures( const QgsFeatureIds & id )
{
if ( mFidColName.isEmpty() )
return false;

QString featureIds;
for ( QgsFeatureIds::const_iterator it = id.begin(); it != id.end(); ++it )
{
Expand Down Expand Up @@ -1156,7 +1162,10 @@ bool QgsMssqlProvider::deleteFeatures( const QgsFeatureIds & id )

int QgsMssqlProvider::capabilities() const
{
return CreateSpatialIndex | CreateAttributeIndex | AddFeatures | DeleteFeatures |
if (mFidColName.isEmpty())
return CreateSpatialIndex | CreateAttributeIndex | AddFeatures | AddAttributes;
else
return CreateSpatialIndex | CreateAttributeIndex | AddFeatures | DeleteFeatures |
ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes |
QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mssql/qgsmssqlprovider.h
Expand Up @@ -71,7 +71,7 @@ class QgsMssqlGeometryParser

protected:
void CopyBytes( void* src, int len );
void CopyCoordinates( unsigned char* src );
void CopyCoordinates( int iPoint );
void CopyPoint( int iPoint );
void ReadPoint( int iShape );
void ReadMultiPoint( int iShape );
Expand Down

0 comments on commit 3cf8840

Please sign in to comment.