void Loader::onImport( const location& loc, const std::string& importTypeName ) { // Notice: the type is not loaded now in order to avoid cyclic dependencies. if( _typeBuilder.isValid() ) { pushError( loc, "all import clauses must come before the type specification" ); return; } size_t lastDotPos = importTypeName.rfind( '.' ); if( lastDotPos == std::string::npos ) { pushError( loc, "type is in the same namespace and does not require importing" ); return; } std::string localTypeName = importTypeName.substr( lastDotPos + 1 ); // checks whether a type with the same local name was already imported ImportTypeMap::iterator it = _importedTypes.find( localTypeName ); if( it != _importedTypes.end() ) { PUSH_ERROR( loc, "import '" << importTypeName << "' conflicts with a " "previous import at line " << it->second.loc.begin.line ); return; } _importedTypes.insert( ImportTypeMap::value_type( localTypeName, ImportInfo( importTypeName, loc ) ) ); }
IType* TypeLoader::resolveType( const csl::location& loc, const std::string& typeName, bool isArray ) { try { if( isArray ) { IType* elementType = resolveType( loc, typeName ); if( !elementType ) { assert( getError() != NULL ); pushError( loc, "error loading array element type" ); return NULL; } return _typeManager->getArrayOf( elementType ); } // try to find an imported type aliased as 'typeName' IType* type = findImportedType( typeName ); if( type ) return type; // try to find an existing type named 'typeName' type = findDependency( typeName ); if( type ) return type; // try to load a type named 'typeName' return loadDependency( typeName ); } catch( co::Exception& e ) { pushError( loc, e.getMessage() ); return NULL; } }
void QgsWFSProvider::handleException( const QDomDocument& serverResponse ) { QgsDebugMsg( QString( "server response: %1" ).arg( serverResponse.toString() ) ); QDomElement exceptionElem = serverResponse.documentElement(); if ( exceptionElem.isNull() ) { pushError( tr( "empty response" ) ); return; } if ( exceptionElem.tagName() == "ServiceExceptionReport" ) { pushError( tr( "WFS service exception:%1" ).arg( exceptionElem.firstChildElement( "ServiceException" ).text() ) ); return; } if ( exceptionElem.tagName() == "WFS_TransactionResponse" ) { pushError( tr( "unsuccessful service response: %1" ).arg( exceptionElem.firstChildElement( "TransactionResult" ).firstChildElement( "Message" ).text() ) ); return; } if ( exceptionElem.tagName() == "ExceptionReport" ) { QDomElement exception = exceptionElem.firstChildElement( "Exception" ); pushError( tr( "WFS exception report (code=%1 text=%2)" ) .arg( exception.attribute( "exceptionCode", tr( "missing" ) ), exception.firstChildElement( "ExceptionText" ).text() ) ); return; } pushError( tr( "unhandled response: %1" ).arg( exceptionElem.tagName() ) ); }
bool QgsDb2Provider::setSubsetString( const QString& theSQL, bool ) { QString prevWhere = mSqlWhereClause; QgsDebugMsg( theSQL ); mSqlWhereClause = theSQL.trimmed(); QString sql = QString( "SELECT COUNT(*) FROM " ); sql += QString( "%1.%2" ).arg( mSchemaName, mTableName ); if ( !mSqlWhereClause.isEmpty() ) { sql += QString( " WHERE %1" ).arg( mSqlWhereClause ); } if ( !openDatabase( mDatabase ) ) { return false; } QSqlQuery query = QSqlQuery( mDatabase ); query.setForwardOnly( true ); QgsDebugMsg( sql ); if ( !query.exec( sql ) ) { pushError( query.lastError().text() ); mSqlWhereClause = prevWhere; QgsDebugMsg( query.lastError().text() ); return false; } if ( query.isActive() && query.next() ) { mNumberFeatures = query.value( 0 ).toInt(); QgsDebugMsg( QString( "count: %1" ).arg( mNumberFeatures ) ); } else { pushError( query.lastError().text() ); mSqlWhereClause = prevWhere; QgsDebugMsg( query.lastError().text() ); return false; } QgsDataSourceUri anUri = QgsDataSourceUri( dataSourceUri() ); anUri.setSql( mSqlWhereClause ); setDataSourceUri( anUri.uri() ); mExtent.setMinimal(); emit dataChanged(); return true; }
void Loader::onTypeSpec( const location& kLoc, TypeKind kind, const location& nLoc, const std::string& name ) { if( _typeBuilder.isValid() ) pushError( kLoc, "only one type specification is allowed per file" ); else if( name != _cslFileBaseName ) pushError( nLoc, "the name of the defined type must match its filename" ); else { _typeBuilder = createTypeBuilder( name, kind ); onElement( std::string() ); resolveImports(); } }
bool Loader::parse( const std::string& filename ) { _filename = &filename; // extract the CSL file's base name size_t startPos = filename.rfind( CORAL_OS_DIR_SEP ); startPos = ( startPos == std::string::npos ? 0 : startPos + 1 ); size_t lastDotPos = filename.rfind( '.' ); _cslFileBaseName.assign( filename, startPos, lastDotPos - startPos ); // open file FILE* file = fopen( filename.c_str(), "rt" ); if( !file ) { pushError( filename, "could not open file" ); return false; } yyscan_t scanner; csl_lex_init( &scanner ); csl_set_in( file, scanner ); try { Parser parser( *this, scanner ); //parser.set_debug_level( 1 ); if( parser.parse() != 0 ) { assert( getError() ); if( !getError() ) pushError( filename, "unexpected parse error" ); } } catch( std::exception& e ) { pushError( filename, std::string( "unexpected exception: " ) + e.what() ); } catch( ... ) { pushError( filename, "unexpected unknown exception" ); } csl_lex_destroy( scanner ); fclose( file ); _filename = NULL; return !_error.isValid(); }
bool enumExists(MavenCompiler* c, string name) { StringList items = split('.', name); int namespaceID = -1, objectID = -1; if(items.length() == 1) { // recognise ambiguous objects vector<int> found; for(namespaceID = 0; namespaceID < c->namespaces->length(); ++namespaceID) { objectID = findEnumID(c, namespaceID, items[0]); if(objectID >= 0) found.push_back(namespaceID); } --namespaceID; if(found.size() > 1) pushError(c, "Ambiguous enumerator '%s'", items[0]); return (found.size() == 1); } else if(items.length() == 2) { namespaceID = findNamespaceID(c, items[0]); if(namespaceID < 0) return false; objectID = findEnumID(c, namespaceID, items[1]); return (objectID >= 0); } return false; }
void Loader::onAnnotationData( const location& loc, const std::string& fieldName, const Any& value ) { IAnnotation* annotation = _annotations.back().annotations.back().get(); try { IInterface* itf = annotation->getInterface(); IMember* m = itf->getMember( fieldName ); if( !m || m->getKind() != MK_FIELD ) { PUSH_ERROR( loc, "annotation type '" << itf->getFullName() << "' has no field named '" << fieldName << "'" ); return; } ICompositeType* ct = m->getOwner(); IReflector* reflector = ct->getReflector(); if( !reflector ) { PUSH_ERROR( loc, "annotation type '" << ct->getFullName() << "' has no reflector" ); return; } reflector->setField( annotation, static_cast<IField*>( m ), value ); } catch( Exception& e ) { pushError( loc, e.getMessage() ); PUSH_ERROR( loc, "error setting annotation field '" << fieldName << "'" ); } }
string compilerFunctionSelector(MavenCompiler* c, string signature, string args, string& type) { // find the function we are trying to select if(signature.substr(0, 10) != "<Function:") { pushError(c, "@selector is not a function"); return MAVEN_INVALID; } StringList parts = split(',', signature.substr(10, signature.length() - 11)); int fnID = atoi(parts[0].c_str()); int foID = atoi(parts[1].c_str()); int fID = atoi(parts[2].c_str()); string ptrType = c->namespaces->at(fnID).objects->at(foID)->functions->at(fID).returnType; // build the selector function args = trim(args); if(pushSelector(c, args)) { #if MAVEN_OS == 1 c->postLines.push_back("void* " + args + "$selector(void* v) {"); #elif MAVEN_OS == 2 c->postLines.push_back("int " + args + "$selector(void* v) {"); #endif c->postLines.push_back("maven::objectArray* argv = (maven::objectArray*) v;"); if(ptrType != "void") c->postLines.push_back(ptrType + " *r = new " + ptrType + "[1];"); c->postLines.push_back("try {"); c->postLines.push_back("if(argv->length != " + intToString(c->namespaces->at(fnID).objects->at(foID)->functions->at(fID).args.length()) + ") throw new maven::SelectorException();"); string caller = ""; for(int i = 0; i < c->namespaces->at(fnID).objects->at(foID)->functions->at(fID).args.length(); ++i) { if(caller != "") caller += ","; caller += "argv->a[" + intToString(i) + "]->toFloat()"; } c->postLines.push_back(string(c->namespaces->at(fnID).name + "::" + c->namespaces->at(fnID).objects->at(foID)->name + "::" + args + "(") + caller + ");"); c->postLines.push_back("} catch(maven::Exception* caughtGlobalException) {"); c->postLines.push_back(" std::cout << caughtGlobalException->description()->s << std::endl;"); c->postLines.push_back("}"); if(ptrType != "void") { #if MAVEN_OS == 1 c->postLines.push_back("return (void*) r;"); #elif MAVEN_OS == 2 c->postLines.push_back("return 0;"); #endif } c->postLines.push_back("}"); } // all done type = "maven.Selector"; return "new maven::Selector(" + args + "$selector)"; }
void Loader::onPort( const location& loc, bool isFacet, const std::string& name ) { IType* type = getLastDeclaredType(); if( getError() ) return; if( type->getKind() != TK_INTERFACE ) { pushError( loc, "an interface type was expected" ); return; } CATCH_ERRORS( loc, _typeBuilder->definePort( name, static_cast<IInterface*>( type ), isFacet ) ); onElement( name ); }
/** * @brief Initialize an error object * * @param message The message of the error */ void errorInitial( char *message ) { Error *e; // printf("A wild error has appeared\n"); // e = (Error *) malloc(sizeof(Error)); //add to errList e->message = (char*) malloc(sizeof(char) * strlen(message)); strcpy(e->message, message); e->message_length = strlen(message); e->line_number = g_lineNum - g_headerLines; e->column_start = g_lineCol; e->num_characters = 0; e_count++; pushError(e); }
void Loader::onAnnotation( const location& loc, const std::string& name, bool hasData ) { std::string componentName; componentName.reserve( name.size() + 10 ); componentName.append( name ); componentName.append( "Annotation" ); IType* type = resolveType( loc, componentName ); if( !type ) { PUSH_ERROR( loc, "error loading annotation type '" << componentName << "'" ); return; } if( type->getKind() != TK_COMPONENT ) { PUSH_ERROR( loc, "annotation type '" << componentName << "' is not a component" ); return; } try { RefPtr<IAnnotation> annotation; if( hasData ) { RefPtr<IObject> object( type->getReflector()->newInstance() ); annotation = getAnnotationFrom( object.get() ); } else { annotation = getDefaultAnnotationInstance( type ); } if( _annotations.empty() ) _annotations.push_back( AnnotationRecord() ); _annotations.back().annotations.push_back( annotation.get() ); } catch( Exception& e ) { pushError( loc, e.getMessage() ); } }
IType* TypeLoader::loadType() { try { std::string fullPath; std::string relativePath; if( findCSL( _fullTypeName, fullPath, relativePath ) ) { INamespace* ns = _typeManager->getRootNS(); // iterate over all subparts StringTokenizer st( relativePath, CORAL_OS_DIR_SEP_STR ); st.nextToken(); std::string currentToken = st.getToken(); while( st.nextToken() ) { ns = getOrCreateChildNamespace( ns, currentToken ); currentToken = st.getToken(); } _namespace = ns; if( parse( fullPath ) ) { if( isRootLoader() ) _typeManager->getTransaction()->commit(); return getType(); } } } catch( co::Exception& e ) { pushError( e.getMessage() ); } if( isRootLoader() ) _typeManager->getTransaction()->rollback(); return NULL; }
QgsAfsProvider::QgsAfsProvider( const QString &uri, const ProviderOptions &options ) : QgsVectorDataProvider( uri, options ) { mSharedData.reset( new QgsAfsSharedData() ); mSharedData->mGeometryType = QgsWkbTypes::Unknown; mSharedData->mDataSource = QgsDataSourceUri( uri ); const QString authcfg = mSharedData->mDataSource.authConfigId(); // Set CRS mSharedData->mSourceCRS.createFromString( mSharedData->mDataSource.param( QStringLiteral( "crs" ) ) ); // Get layer info QString errorTitle, errorMessage; const QString referer = mSharedData->mDataSource.param( QStringLiteral( "referer" ) ); if ( !referer.isEmpty() ) mRequestHeaders[ QStringLiteral( "Referer" )] = referer; const QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( mSharedData->mDataSource.param( QStringLiteral( "url" ) ), authcfg, errorTitle, errorMessage, mRequestHeaders ); if ( layerData.isEmpty() ) { pushError( errorTitle + ": " + errorMessage ); appendError( QgsErrorMessage( tr( "getLayerInfo failed" ), QStringLiteral( "AFSProvider" ) ) ); return; } mLayerName = layerData[QStringLiteral( "name" )].toString(); mLayerDescription = layerData[QStringLiteral( "description" )].toString(); // Set extent QStringList coords = mSharedData->mDataSource.param( QStringLiteral( "bbox" ) ).split( ',' ); bool limitBbox = false; if ( coords.size() == 4 ) { bool xminOk = false, yminOk = false, xmaxOk = false, ymaxOk = false; mSharedData->mExtent.setXMinimum( coords[0].toDouble( &xminOk ) ); mSharedData->mExtent.setYMinimum( coords[1].toDouble( &yminOk ) ); mSharedData->mExtent.setXMaximum( coords[2].toDouble( &xmaxOk ) ); mSharedData->mExtent.setYMaximum( coords[3].toDouble( &ymaxOk ) ); if ( !xminOk || !yminOk || !xmaxOk || !ymaxOk ) mSharedData->mExtent = QgsRectangle(); else { // user has set a bounding box limit on the layer - so we only EVER fetch features from this extent limitBbox = true; } } const QVariantMap layerExtentMap = layerData[QStringLiteral( "extent" )].toMap(); bool xminOk = false, yminOk = false, xmaxOk = false, ymaxOk = false; QgsRectangle originalExtent; originalExtent.setXMinimum( layerExtentMap[QStringLiteral( "xmin" )].toDouble( &xminOk ) ); originalExtent.setYMinimum( layerExtentMap[QStringLiteral( "ymin" )].toDouble( &yminOk ) ); originalExtent.setXMaximum( layerExtentMap[QStringLiteral( "xmax" )].toDouble( &xmaxOk ) ); originalExtent.setYMaximum( layerExtentMap[QStringLiteral( "ymax" )].toDouble( &ymaxOk ) ); if ( mSharedData->mExtent.isEmpty() && ( !xminOk || !yminOk || !xmaxOk || !ymaxOk ) ) { appendError( QgsErrorMessage( tr( "Could not retrieve layer extent" ), QStringLiteral( "AFSProvider" ) ) ); return; } QgsCoordinateReferenceSystem extentCrs = QgsArcGisRestUtils::parseSpatialReference( layerExtentMap[QStringLiteral( "spatialReference" )].toMap() ); if ( mSharedData->mExtent.isEmpty() && !extentCrs.isValid() ) { appendError( QgsErrorMessage( tr( "Could not parse spatial reference" ), QStringLiteral( "AFSProvider" ) ) ); return; } if ( xminOk && yminOk && xmaxOk && ymaxOk ) { QgsLayerMetadata::SpatialExtent spatialExtent; spatialExtent.bounds = QgsBox3d( originalExtent ); spatialExtent.extentCrs = extentCrs; QgsLayerMetadata::Extent metadataExtent; metadataExtent.setSpatialExtents( QList< QgsLayerMetadata::SpatialExtent >() << spatialExtent ); mLayerMetadata.setExtent( metadataExtent ); } if ( extentCrs.isValid() ) { mLayerMetadata.setCrs( extentCrs ); } if ( mSharedData->mExtent.isEmpty() ) { mSharedData->mExtent = originalExtent; Q_NOWARN_DEPRECATED_PUSH mSharedData->mExtent = QgsCoordinateTransform( extentCrs, mSharedData->mSourceCRS ).transformBoundingBox( mSharedData->mExtent ); Q_NOWARN_DEPRECATED_POP }
QgsAfsProvider::QgsAfsProvider( const QString &uri ) : QgsVectorDataProvider( uri ) , mValid( false ) , mObjectIdFieldIdx( -1 ) { mSharedData.reset( new QgsAfsSharedData() ); mSharedData->mGeometryType = QgsWkbTypes::Unknown; mSharedData->mDataSource = QgsDataSourceUri( uri ); // Set CRS mSharedData->mSourceCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mSharedData->mDataSource.param( QStringLiteral( "crs" ) ) ); // Get layer info QString errorTitle, errorMessage; const QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( mSharedData->mDataSource.param( QStringLiteral( "url" ) ), errorTitle, errorMessage ); if ( layerData.isEmpty() ) { pushError( errorTitle + ": " + errorMessage ); appendError( QgsErrorMessage( tr( "getLayerInfo failed" ), QStringLiteral( "AFSProvider" ) ) ); return; } mLayerName = layerData[QStringLiteral( "name" )].toString(); mLayerDescription = layerData[QStringLiteral( "description" )].toString(); // Set extent QStringList coords = mSharedData->mDataSource.param( QStringLiteral( "bbox" ) ).split( ',' ); if ( coords.size() == 4 ) { bool xminOk = false, yminOk = false, xmaxOk = false, ymaxOk = false; mSharedData->mExtent.setXMinimum( coords[0].toDouble( &xminOk ) ); mSharedData->mExtent.setYMinimum( coords[1].toDouble( &yminOk ) ); mSharedData->mExtent.setXMaximum( coords[2].toDouble( &xmaxOk ) ); mSharedData->mExtent.setYMaximum( coords[3].toDouble( &ymaxOk ) ); if ( !xminOk || !yminOk || !xmaxOk || !ymaxOk ) mSharedData->mExtent = QgsRectangle(); } const QVariantMap layerExtentMap = layerData[QStringLiteral( "extent" )].toMap(); bool xminOk = false, yminOk = false, xmaxOk = false, ymaxOk = false; QgsRectangle originalExtent; originalExtent.setXMinimum( layerExtentMap[QStringLiteral( "xmin" )].toDouble( &xminOk ) ); originalExtent.setYMinimum( layerExtentMap[QStringLiteral( "ymin" )].toDouble( &yminOk ) ); originalExtent.setXMaximum( layerExtentMap[QStringLiteral( "xmax" )].toDouble( &xmaxOk ) ); originalExtent.setYMaximum( layerExtentMap[QStringLiteral( "ymax" )].toDouble( &ymaxOk ) ); if ( mSharedData->mExtent.isEmpty() && ( !xminOk || !yminOk || !xmaxOk || !ymaxOk ) ) { appendError( QgsErrorMessage( tr( "Could not retrieve layer extent" ), QStringLiteral( "AFSProvider" ) ) ); return; } QgsCoordinateReferenceSystem extentCrs = QgsArcGisRestUtils::parseSpatialReference( layerExtentMap[QStringLiteral( "spatialReference" )].toMap() ); if ( mSharedData->mExtent.isEmpty() && !extentCrs.isValid() ) { appendError( QgsErrorMessage( tr( "Could not parse spatial reference" ), QStringLiteral( "AFSProvider" ) ) ); return; } if ( xminOk && yminOk && xmaxOk && ymaxOk ) { QgsLayerMetadata::SpatialExtent spatialExtent; spatialExtent.bounds = QgsBox3d( originalExtent ); spatialExtent.extentCrs = extentCrs; QgsLayerMetadata::Extent metadataExtent; metadataExtent.setSpatialExtents( QList< QgsLayerMetadata::SpatialExtent >() << spatialExtent ); mLayerMetadata.setExtent( metadataExtent ); } if ( extentCrs.isValid() ) { mLayerMetadata.setCrs( extentCrs ); } if ( mSharedData->mExtent.isEmpty() ) { mSharedData->mExtent = originalExtent; Q_NOWARN_DEPRECATED_PUSH mSharedData->mExtent = QgsCoordinateTransform( extentCrs, mSharedData->mSourceCRS ).transformBoundingBox( mSharedData->mExtent ); Q_NOWARN_DEPRECATED_POP }
bool QgsDb2Provider::addFeatures( QgsFeatureList & flist ) { QgsDebugMsg( "mGeometryColType: " + mGeometryColType ); int writeCount = 0; bool copyOperation = false; if ( !mDatabase.isOpen() ) { QString errMsg; mDatabase = getDatabase( mConnInfo, errMsg ); if ( !errMsg.isEmpty() ) { QgsDebugMsg( "getDatabase failed: " + errMsg ); return false; } } if ( !mDatabase.transaction() ) { QgsDebugMsg( "transaction failed" ); return false; } QSqlQuery query = QSqlQuery( mDatabase ); query.setForwardOnly( true ); QSqlQuery queryFid = QSqlQuery( mDatabase ); queryFid.setForwardOnly( true ); QgsFeature it = flist.at( 0 ); QString statement; QString values; statement = QString( "INSERT INTO %1.%2 (" ).arg( mSchemaName, mTableName ); bool first = true; // Get the first geometry and its wkbType as when we are doing drag/drop, // the wkbType is not passed to the DB2 provider from QgsVectorLayerImport // Can't figure out how to resolved "unreferenced" wkbType compile message // Don't really do anything with it at this point #if 0 QgsGeometry *geom = it.geometry(); QgsWkbTypes::Type wkbType = geom->wkbType(); QgsDebugMsg( QString( "wkbType: %1" ).arg( wkbType ) ); QgsDebugMsg( QString( "mWkbType: %1" ).arg( mWkbType ) ); #endif QgsAttributes attrs = it.attributes(); QgsDebugMsg( QString( "attrs.count: %1" ).arg( attrs.count() ) ); QgsDebugMsg( QString( "fields.count: %1" ).arg( mAttributeFields.count() ) ); if ( mAttributeFields.count() == ( attrs.count() + 1 ) ) { copyOperation = true; // FID is first field but no attribute in attrs } else if ( mAttributeFields.count() != attrs.count() ) { QgsDebugMsg( "Count mismatch - failing" ); return false; } if ( attrs.count() != mAttributeFields.count() ) { QgsDebugMsg( "field counts don't match" ); // return false; } for ( int i = 0; i < mAttributeFields.count(); ++i ) { QgsField fld = mAttributeFields.at( i ); QgsDebugMsg( QString( "i: %1; got field: %2" ).arg( i ).arg( fld.name() ) ); if ( fld.name().isEmpty() ) continue; // invalid if ( mFidColName == fld.name() ) continue; // skip identity field // if ( mDefaultValues.contains( i ) && mDefaultValues[i] == attrs.at( i ) ) // continue; // skip fields having default values if ( !first ) { statement += ','; values += ','; } else first = false; statement += QString( "%1" ).arg( fld.name() ); values += QString( "?" ); } // append geometry column name if ( !mGeometryColName.isEmpty() ) { if ( !first ) { statement += ','; values += ','; } statement += QString( "%1" ).arg( mGeometryColName ); values += QString( "db2gse.%1(CAST (%2 AS BLOB(2M)),%3)" ) .arg( mGeometryColType, QString( "?" ), QString::number( mSRId ) ); } QgsDebugMsg( statement ); QgsDebugMsg( values ); statement += ") VALUES (" + values + ')'; QgsDebugMsg( statement ); QgsDebugMsg( "Prepare statement" ); // use prepared statement to prevent from sql injection if ( !query.prepare( statement ) ) { QString msg = query.lastError().text(); QgsDebugMsg( msg ); pushError( msg ); return false; } for ( QgsFeatureList::iterator it = flist.begin(); it != flist.end(); ++it ) { attrs = it->attributes(); int fieldIdx = 0; if ( copyOperation ) { fieldIdx = 1; // skip first (FID) field if copying from shapefile } int bindIdx = 0; for ( int i = 0; i < attrs.count(); i++ ) { QgsField fld = mAttributeFields.at( fieldIdx++ ); if ( fld.name().isEmpty() ) continue; // invalid if ( mFidColName == fld.name() ) continue; // skip identity field // if ( mDefaultValues.contains( i ) && mDefaultValues[i] == attrs.at( i ) ) // continue; // skip fields having default values QVariant::Type type = fld.type(); if ( attrs.at( i ).isNull() || !attrs.at( i ).isValid() ) { // binding null values if ( type == QVariant::Date || type == QVariant::DateTime ) query.bindValue( bindIdx, QVariant( QVariant::String ) ); else query.bindValue( bindIdx, QVariant( type ) ); } else if ( type == QVariant::Int ) { // binding an INTEGER value query.bindValue( bindIdx, attrs.at( i ).toInt() ); } else if ( type == QVariant::Double ) { // binding a DOUBLE value query.bindValue( bindIdx, attrs.at( i ).toDouble() ); } else if ( type == QVariant::String ) { // binding a TEXT value query.bindValue( bindIdx, attrs.at( i ).toString() ); } else if ( type == QVariant::Time ) { // binding a TIME value query.bindValue( bindIdx, attrs.at( i ).toTime().toString( Qt::ISODate ) ); } else if ( type == QVariant::Date ) { // binding a DATE value query.bindValue( bindIdx, attrs.at( i ).toDate().toString( Qt::ISODate ) ); } else if ( type == QVariant::DateTime ) { // binding a DATETIME value query.bindValue( bindIdx, attrs.at( i ).toDateTime().toString( Qt::ISODate ) ); } else { query.bindValue( bindIdx, attrs.at( i ) ); } #if 0 QgsDebugMsg( QString( "bound i: %1; name: %2; value: %3; bindIdx: %4" ). arg( i ).arg( fld.name() ).arg( attrs.at( i ).toString() ).arg( bindIdx ) ); #endif bindIdx++; } if ( !mGeometryColName.isEmpty() ) { QgsGeometry geom = it->geometry(); QByteArray bytea = QByteArray(( char* )geom.asWkb(), ( int ) geom.wkbSize() ); query.bindValue( bindIdx, bytea, QSql::In | QSql::Binary ); } QList<QVariant> list = query.boundValues().values(); // Show bound values #if 0 for ( int i = 0; i < list.size(); ++i ) { QgsDebugMsg( QString( "i: %1; value: %2; type: %3" ) .arg( i ).arg( list.at( i ).toString().toLatin1().data() ).arg( list.at( i ).typeName() ) ); } #endif if ( !query.exec() ) { QString msg = query.lastError().text(); QgsDebugMsg( msg ); if ( !mSkipFailures ) { pushError( msg ); return false; } } statement = QString( "select IDENTITY_VAL_LOCAL() AS IDENTITY " "FROM SYSIBM.SYSDUMMY1" ); // QgsDebugMsg( statement ); if ( !queryFid.exec( statement ) ) { QString msg = query.lastError().text(); QgsDebugMsg( msg ); if ( !mSkipFailures ) { pushError( msg ); return false; } } if ( !queryFid.next() ) { QString msg = query.lastError().text(); QgsDebugMsg( msg ); if ( !mSkipFailures ) { pushError( msg ); return false; } } it->setFeatureId( queryFid.value( 0 ).toLongLong() ); writeCount++; // QgsDebugMsg( QString( "count: %1; featureId: %2" ).arg( writeCount ).arg( queryFid.value( 0 ).toLongLong() ) ); } bool commitStatus = mDatabase.commit(); QgsDebugMsg( QString( "commitStatus: %1; write count: %2; featureId: %3" ) .arg( commitStatus ).arg( writeCount ).arg( queryFid.value( 0 ).toLongLong() ) ); if ( !commitStatus ) { pushError( "Commit of new features failed" ); return false; } return true; }
FinalRepresentation IntermediateRepresentator::transform(const TransformationParameters& parameters, const CompileErrorList& parsingErrors, MemoryAccess& memoryAccess) { auto errors = parsingErrors; if (_currentOutput) { errors.pushError(_currentOutput->positionInterval(), "Macro not closed. Missing a macro end directive?"); } PrecompileImmutableArguments precompileArguments(parameters.architecture(), parameters.generator()); SymbolGraph graph; MacroDirectiveTable macroTable; for (const auto& command : _commandList) { command->precompile(precompileArguments, errors, graph, macroTable); } IntermediateMacroInstruction::replaceWithMacros( _commandList.begin(), _commandList.end(), macroTable, errors); auto macroList = generateMacroInformation(); auto preliminaryEvaluation = graph.evaluate(); if (!evaluateGraph(preliminaryEvaluation, errors)) { return FinalRepresentation({}, errors, macroList); } SymbolReplacer preliminaryReplacer(preliminaryEvaluation); MemoryAllocator allocator(parameters.allocator()); SectionTracker tracker; auto allowedSize = memoryAccess.getMemorySize().get(); IntermediateOperationPointer firstMemoryExceedingOperation(nullptr); AllocateMemoryImmutableArguments allocateMemoryArguments(precompileArguments, preliminaryReplacer); for (const auto& command : _commandList) { command->allocateMemory( allocateMemoryArguments, errors, allocator, tracker); if (allocator.estimateSize() > allowedSize && !firstMemoryExceedingOperation) { firstMemoryExceedingOperation = command; } } auto allocatedSize = allocator.calculatePositions(); EnhanceSymbolTableImmutableArguments symbolTableArguments( allocateMemoryArguments, allocator); for (const auto& command : _commandList) { command->enhanceSymbolTable(symbolTableArguments, errors, graph); } auto graphEvaluation = graph.evaluate(); auto graphValid = evaluateGraph(graphEvaluation, errors); auto memoryValid = checkMemorySize( allocatedSize, allowedSize, firstMemoryExceedingOperation, errors); if (!(graphValid && memoryValid)) { return FinalRepresentation({}, errors, macroList); } SymbolReplacer replacer(graphEvaluation); ExecuteImmutableArguments executeArguments(symbolTableArguments, replacer); FinalCommandVector commandOutput; for (const auto& command : _commandList) { command->execute(executeArguments, errors, commandOutput, memoryAccess); } return FinalRepresentation(commandOutput, errors, macroList); }
QgsAfsProvider::QgsAfsProvider( const QString& uri ) : QgsVectorDataProvider( uri ) , mValid( false ) , mGeometryType( QgsWkbTypes::Unknown ) , mObjectIdFieldIdx( -1 ) { mDataSource = QgsDataSourceUri( uri ); // Set CRS mSourceCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mDataSource.param( "crs" ) ); // Get layer info QString errorTitle, errorMessage; QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( mDataSource.param( "url" ), errorTitle, errorMessage ); if ( layerData.isEmpty() ) { pushError( errorTitle + ": " + errorMessage ); appendError( QgsErrorMessage( tr( "getLayerInfo failed" ), "AFSProvider" ) ); return; } mLayerName = layerData["name"].toString(); mLayerDescription = layerData["description"].toString(); // Set extent QStringList coords = mDataSource.param( "bbox" ).split( "," ); if ( coords.size() == 4 ) { bool xminOk = false, yminOk = false, xmaxOk = false, ymaxOk = false; mExtent.setXMinimum( coords[0].toDouble( &xminOk ) ); mExtent.setYMinimum( coords[1].toDouble( &yminOk ) ); mExtent.setXMaximum( coords[2].toDouble( &xmaxOk ) ); mExtent.setYMaximum( coords[3].toDouble( &ymaxOk ) ); if ( !xminOk || !yminOk || !xmaxOk || !ymaxOk ) mExtent = QgsRectangle(); } if ( mExtent.isEmpty() ) { QVariantMap layerExtentMap = layerData["extent"].toMap(); bool xminOk = false, yminOk = false, xmaxOk = false, ymaxOk = false; mExtent.setXMinimum( layerExtentMap["xmin"].toDouble( &xminOk ) ); mExtent.setYMinimum( layerExtentMap["ymin"].toDouble( &yminOk ) ); mExtent.setXMaximum( layerExtentMap["xmax"].toDouble( &xmaxOk ) ); mExtent.setYMaximum( layerExtentMap["ymax"].toDouble( &ymaxOk ) ); if ( !xminOk || !yminOk || !xmaxOk || !ymaxOk ) { appendError( QgsErrorMessage( tr( "Could not retrieve layer extent" ), "AFSProvider" ) ); return; } QgsCoordinateReferenceSystem extentCrs = QgsArcGisRestUtils::parseSpatialReference( layerExtentMap["spatialReference"].toMap() ); if ( !extentCrs.isValid() ) { appendError( QgsErrorMessage( tr( "Could not parse spatial reference" ), "AFSProvider" ) ); return; } mExtent = QgsCoordinateTransform( extentCrs, mSourceCRS ).transformBoundingBox( mExtent ); } // Read fields foreach ( const QVariant& fieldData, layerData["fields"].toList() ) { QVariantMap fieldDataMap = fieldData.toMap(); QString fieldName = fieldDataMap["name"].toString(); QVariant::Type type = QgsArcGisRestUtils::mapEsriFieldType( fieldDataMap["type"].toString() ); if ( fieldName == "geometry" || type == QVariant::Invalid ) { QgsDebugMsg( QString( "Skipping unsupported (or possibly geometry) field" ).arg( fieldName ) ); continue; } QgsField field( fieldName, type, fieldDataMap["type"].toString(), fieldDataMap["length"].toInt() ); mFields.append( field ); } // Determine geometry type bool hasM = layerData["hasM"].toBool(); bool hasZ = layerData["hasZ"].toBool(); mGeometryType = QgsArcGisRestUtils::mapEsriGeometryType( layerData["geometryType"].toString() ); if ( mGeometryType == QgsWkbTypes::Unknown ) { appendError( QgsErrorMessage( tr( "Failed to determine geometry type" ), "AFSProvider" ) ); return; } mGeometryType = QgsWkbTypes::zmType( mGeometryType, hasZ, hasM ); // Read OBJECTIDs of all features: these may not be a continuous sequence, // and we need to store these to iterate through the features. This query // also returns the name of the ObjectID field. QVariantMap objectIdData = QgsArcGisRestUtils::getObjectIds( mDataSource.param( "url" ), errorTitle, errorMessage ); if ( objectIdData.isEmpty() ) { appendError( QgsErrorMessage( tr( "getObjectIds failed: %1 - %2" ).arg( errorTitle ).arg( errorMessage ), "AFSProvider" ) ); return; } if ( !objectIdData["objectIdFieldName"].isValid() || !objectIdData["objectIds"].isValid() ) { appendError( QgsErrorMessage( tr( "Failed to determine objectIdFieldName and/or objectIds" ), "AFSProvider" ) ); return; } mObjectIdFieldName = objectIdData["objectIdFieldName"].toString(); for ( int idx = 0, nIdx = mFields.count(); idx < nIdx; ++idx ) { if ( mFields.at( idx ).name() == mObjectIdFieldName ) { mObjectIdFieldIdx = idx; break; } } foreach ( const QVariant& objectId, objectIdData["objectIds"].toList() ) { mObjectIds.append( objectId.toInt() ); } mValid = true; }
string keywordNew(MavenCompiler* c, string entity, string element, string args, string& type) { string rawType = stripRawType(entity); int depth = ((element != "") ? 1 : 0); //cout << "entity = '" << entity << "', element = '" << element << "', args = '" << args << "', line = " << c->lineNumber << endl; // if this is a native type StringList types; MavenMutability mut; if(isDataType(rawType)) { type = appendArrayDepth(c, rawType, depth); string r = "new maven::" + rawType + "Array(" + dissectCode(c, element, types, mut) + ")"; // bug #54: make sure types is 'int' return r; } // first make sure the class exists bool isEnum = false; type = appendArrayDepth(c, findMavenObjectPath(c, trim(entity)), depth); if(stripRawType(type) == MAVEN_INVALID) { if(enumExists(c, stripRawType(entity))) { isEnum = true; type = c->currentNamespace + "." + appendArrayDepth(c, entity, depth); } else { pushError(c, "Unknown class '%s'", stripRawType(type)); return MAVEN_INVALID; } } int namespaceID, objectID; findClass(c, entity, namespaceID, objectID); smartAssert(namespaceID >= 0); smartAssert(objectID >= 0); // if its a single Object if(element == "") { string r = "new "; r += c->namespaces->at(namespaceID).name + "::" + c->namespaces->at(namespaceID).objects->at(objectID)->name; for(int i = 0; i < depth; ++i) r += "*"; // args is assumed to be predissected. return r + "(" + args + ")"; } else { string elements = dissectCode(c, element, types, mut); // bug #54: make sure types is 'int' string r = "new maven::"; if(isEnum) { r += "int"; rawType = "int"; int nID = findNamespaceID(c, c->currentNamespace); smartAssert(nID >= 0); int enumID = findEnumID(c, nID, entity); smartAssert(enumID >= 0); if(trim(args) == "") args = intToString(c->namespaces->at(nID).enums[enumID].getDefaultValue()); } else r += "object"; string tempVar = getNextTempVariable(c); if(isDataType(rawType)) c->beforeLine += rawType + "* " + tempVar + " = new " + rawType + "[" + elements + "];\n"; else c->beforeLine += "maven::Object** " + tempVar + " = new maven::Object*[" + elements + "];\n"; c->beforeLine += "for(int __INIT = 0; __INIT < " + elements + "; ++__INIT)\n"; if(isDataType(rawType)) { if(trim(args) == "") args = "0"; c->beforeLine += tempVar + "[__INIT] = " + args + ";\n"; } else c->beforeLine += tempVar + "[__INIT] = (maven::Object*) new " + rawType + "(" + args + ");\n"; r += "Array(" + elements + "," + tempVar + ")"; return r; } }