예제 #1
0
int DBObjData::_Write (FILE *file)

	{
	DBInt id, userFlags;
	DBObjRecord *docRec;

	userFlags = Flags () & DBDataFlagUserModeFlags;
	Flags (DBDataFlagUserModeFlags,DBClear);
	if (DBObject::Write (file) == DBFault)		return (DBFault);
	Flags (userFlags,DBSet);
	if (DocsPTR->Write (file) == DBFault)		return (DBFault);
	for (id = 0;id < DocsPTR->ItemNum ();++id)
		{
		if (DocsPTR->WriteItem (file,id) == DBFault) return (DBFault);
		docRec = DocsPTR->Item (id);
		if (((DBVarString *) docRec->Data ())->Write (file) == DBFault) return (DBFault);
		}
	if (ArraysPTR->Write (file) == DBFault)		return (DBFault);
	for (id = 0;id < ArraysPTR->ItemNum ();++id)
		if (ArraysPTR->WriteItem (file,id) == DBFault) return (DBFault);
	TablesPTR->Write (file);
	for (id = 0;id < TablesPTR->ItemNum ();++id)
		if (TablesPTR->WriteItem (file,id) == DBFault) return (DBFault);
	return (BuildFields ());
	}
예제 #2
0
파일: DBObjData.C 프로젝트: bmfekete/RGIS
DBObjData::DBObjData(DBObjData &data) : DBObject(data), DBDataHeader(data._Header()) {
    DBObjTable *table;
    DBObjRecord *record, *obj;
    DBObjTableField *field;
    DBObjectLIST<DBObjTableField> *fields;
    strcpy(FileNameSTR, "");
    TablesPTR = new DBObjectLIST<DBObjTable>(*data.TablesPTR);
    DocsPTR = new DBObjectLIST<DBObjRecord>(*data.DocsPTR);
    ArraysPTR = new DBObjectLIST<DBObjRecord>(*data.ArraysPTR);
    DispPTR = new DBObjectLIST<DBObject>("Data Display");
    LinkedDataPTR = (DBObjData *) NULL;
    for (table = TablesPTR->First(); table != (DBObjTable *) NULL; table = TablesPTR->Next()) {
        fields = table->Fields();
        for (record = table->First(); record != (DBObjRecord *) NULL; record = table->Next()) {
            for (field = fields->First(); field != (DBObjTableField *) NULL; field = fields->Next())
                switch (field->Type()) {
                    case DBTableFieldTableRec:
                    case DBTableFieldDataRec:
                        if ((obj = field->Record(record)) != NULL)
                            field->Record(record, (DBObjRecord *) ((char *) NULL + obj->RowID()));
                        else field->Record(record, (DBObjRecord *) DBFault);
                        break;
                }
        }
    }
    BuildFields();
}
CPLODBCStatement *OGRMSSQLSpatialTableLayer::GetStatement()

{
    if( poStmt == NULL )
    {
        poStmt = BuildStatement(BuildFields());
        iNextShapeId = 0;
    }

    return poStmt;
}
예제 #4
0
void OGRIngresTableLayer::BuildFullQueryStatement()

{
    char *pszFields = BuildFields();

    osQueryStatement.Printf( "SELECT %s FROM %s %s", 
                             pszFields, poFeatureDefn->GetName(), 
                             osWHERE.c_str() );
    
    CPLFree( pszFields );
}
예제 #5
0
int ReadFixedCommand :: Execute( ALib::CommandLine & cmd ) {

	mTrim = ! cmd.HasFlag( FLAG_KEEP );

	BuildFields( cmd );

	IOManager io( cmd );
	string line;

	CSVRow row;
	while( io.ReadLine( line ) ) {
		MakeRow( line, row );
		io.WriteRow( row );
	}

	return 0;
}
예제 #6
0
int DBObjData::_Read(FILE *file, int swap) {
    DBInt id;
    DBObjRecord *docRec;

    if (DBObject::Read(file, swap) == DBFault) return (DBFault);
    if (DocsPTR->Read(file, swap) == DBFault) return (DBFault);
    for (id = 0; id < DocsPTR->ItemNum(); ++id) {
        if (DocsPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
        docRec = DocsPTR->Item(id);
        if (((DBVarString *) docRec->Data())->Read(file, swap) == DBFault) return (DBFault);
    }
    if (ArraysPTR->Read(file, swap) == DBFault) return (DBFault);
    for (id = 0; id < ArraysPTR->ItemNum(); ++id)
        if (ArraysPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
    TablesPTR->Read(file, swap);
    for (id = 0; id < TablesPTR->ItemNum(); ++id)
        if (TablesPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
    return (BuildFields());
}
void OGRMySQLTableLayer::BuildFullQueryStatement()

{
    if( pszQueryStatement != NULL )
    {
        CPLFree( pszQueryStatement );
        pszQueryStatement = NULL;
    }

    char *pszFields = BuildFields();

    pszQueryStatement = (char *) 
        CPLMalloc(strlen(pszFields)+strlen(pszWHERE)
                  +strlen(poFeatureDefn->GetName()) + 40);
    sprintf( pszQueryStatement,
             "SELECT %s FROM `%s` %s", 
             pszFields, poFeatureDefn->GetName(), pszWHERE );
    
    CPLFree( pszFields );
}
예제 #8
0
int WriteFixedCommand :: Execute( ALib::CommandLine & cmd ) {

	GetSkipOptions( cmd );
	BuildFields( cmd );

	IOManager io( cmd );

	if ( cmd.HasFlag( FLAG_RULER ) ) {
		io.Out() << Ruler() << "\n";
	}

	CSVRow row;
	while( io.ReadCSV( row ) ) {
		if ( Skip( row ) ) {
			continue;
		}
		string line = MakeFixedOutput( row );
		io.Out() << line << "\n";
	}

	return 0;
}
OGRFeature *OGRMSSQLSpatialTableLayer::GetFeature( long nFeatureId )

{
    if( pszFIDColumn == NULL )
        return OGRMSSQLSpatialLayer::GetFeature( nFeatureId );

    ClearStatement();

    iNextShapeId = nFeatureId;

    poStmt = new CPLODBCStatement( poDS->GetSession() );
    CPLString osFields = BuildFields();
    poStmt->Appendf( "select %s from %s where %s = %ld", osFields.c_str(), 
        poFeatureDefn->GetName(), pszFIDColumn, nFeatureId );

    if( !poStmt->ExecuteSQL() )
    {
        delete poStmt;
        poStmt = NULL;
        return NULL;
    }

    return GetNextRawFeature();
}
예제 #10
0
OGRFeature *OGRIngresTableLayer::GetFeature( long nFeatureId )

{
    if( pszFIDColumn == NULL )
        return OGRIngresLayer::GetFeature( nFeatureId );

/* -------------------------------------------------------------------- */
/*      Discard any existing resultset.                                 */
/* -------------------------------------------------------------------- */
    ResetReading();

/* -------------------------------------------------------------------- */
/*      Prepare query command that will just fetch the one record of    */
/*      interest.                                                       */
/* -------------------------------------------------------------------- */
    char        *pszFieldList = BuildFields();
    char        *pszCommand = (char *) CPLMalloc(strlen(pszFieldList)+2000);

    sprintf( pszCommand, 
             "SELECT %s FROM %s WHERE %s = %ld", 
             pszFieldList, poFeatureDefn->GetName(), pszFIDColumn, 
             nFeatureId );
    CPLFree( pszFieldList );

/* -------------------------------------------------------------------- */
/*      Issue the command.                                              */
/* -------------------------------------------------------------------- */
    if( ingres_query( poDS->GetConn(), pszCommand ) )
    {
        poDS->ReportError( pszCommand );
        return NULL;
    }
    CPLFree( pszCommand );

    hResultSet = ingres_store_result( poDS->GetConn() );
    if( hResultSet == NULL )
    {
        poDS->ReportError( "ingres_store_result() failed on query." );
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Fetch the result record.                                        */
/* -------------------------------------------------------------------- */
    char **papszRow;
    unsigned long *panLengths;

    papszRow = ingres_fetch_row( hResultSet );
    if( papszRow == NULL )
        return NULL;

    panLengths = ingres_fetch_lengths( hResultSet );

/* -------------------------------------------------------------------- */
/*      Transform into a feature.                                       */
/* -------------------------------------------------------------------- */
    iNextShapeId = nFeatureId;

    OGRFeature *poFeature = RecordToFeature( papszRow, panLengths );

    iNextShapeId = 0;

/* -------------------------------------------------------------------- */
/*      Cleanup                                                         */
/* -------------------------------------------------------------------- */
    if( hResultSet != NULL )
        ingres_free_result( hResultSet );
 		hResultSet = NULL;

    return poFeature;
}
예제 #11
0
OGRDODSSequenceLayer::OGRDODSSequenceLayer( OGRDODSDataSource *poDSIn, 
                                            const char *pszTargetIn,
                                            AttrTable *poOGRLayerInfoIn )

        : OGRDODSLayer( poDSIn, pszTargetIn, poOGRLayerInfoIn )

{
    pszSubSeqPath = "profile"; // hardcode for now. 
    panSubSeqSize = NULL;
    iLastSuperSeq = -1;

/* -------------------------------------------------------------------- */
/*      What is the layer name?                                         */
/* -------------------------------------------------------------------- */
    string oLayerName;
    const char *pszLayerName = pszTargetIn;

    if( poOGRLayerInfo != NULL )
    {
        oLayerName = poOGRLayerInfo->get_attr( "layer_name" );
        if( strlen(oLayerName.c_str()) > 0 )
            pszLayerName = oLayerName.c_str();
    }
        
    poFeatureDefn = new OGRFeatureDefn( pszLayerName );
    poFeatureDefn->Reference();

/* -------------------------------------------------------------------- */
/*      Fetch the target variable.                                      */
/* -------------------------------------------------------------------- */
    Sequence *seq = dynamic_cast<Sequence *>(poDS->poDDS->var( pszTargetIn ));

    poTargetVar = seq;
    poSuperSeq = FindSuperSequence( seq );

/* -------------------------------------------------------------------- */
/*      X/Y/Z fields.                                                   */
/* -------------------------------------------------------------------- */
    if( poOGRLayerInfo != NULL )
    {
        AttrTable *poField = poOGRLayerInfo->find_container("x_field");
        if( poField != NULL )
            oXField.Initialize( poField, poTargetVar, poSuperSeq );

        poField = poOGRLayerInfo->find_container("y_field");
        if( poField != NULL )
            oYField.Initialize( poField, poTargetVar, poSuperSeq );

        poField = poOGRLayerInfo->find_container("z_field");
        if( poField != NULL )
            oZField.Initialize( poField, poTargetVar, poSuperSeq );
    }

/* -------------------------------------------------------------------- */
/*      If we have no layerinfo, then check if there are obvious x/y    */
/*      fields.                                                         */
/* -------------------------------------------------------------------- */
    else
    {
        string oTargName = pszTargetIn;
        string oSSTargName;
        string x, y;

        if( poSuperSeq != NULL )
            oSSTargName = OGRDODSGetVarPath( poSuperSeq );
        else
            oSSTargName = "impossiblexxx";

        if( poDS->poDDS->var( oTargName + ".lon" ) != NULL 
            && poDS->poDDS->var( oTargName + ".lat" ) != NULL )
        {
            oXField.Initialize( (oTargName + ".lon").c_str(), "dds",
                                poTargetVar, poSuperSeq );
            oYField.Initialize( (oTargName + ".lat").c_str(), "dds",
                                poTargetVar, poSuperSeq );
        }
        else if( poDS->poDDS->var( oSSTargName + ".lon" ) != NULL 
                 && poDS->poDDS->var( oSSTargName + ".lat" ) != NULL )
        {
            oXField.Initialize( (oSSTargName + ".lon").c_str(), "dds",
                                poTargetVar, poSuperSeq );
            oYField.Initialize( (oSSTargName + ".lat").c_str(), "dds",
                                poTargetVar, poSuperSeq );
        }
    }

/* -------------------------------------------------------------------- */
/*      Add fields for the contents of the sequence.                    */
/* -------------------------------------------------------------------- */
    Sequence::Vars_iter v_i;

    for( v_i = seq->var_begin(); v_i != seq->var_end(); v_i++ )
        BuildFields( *v_i, NULL, NULL );

/* -------------------------------------------------------------------- */
/*      Add fields for the contents of the super-sequence if we have    */
/*      one.                                                            */
/* -------------------------------------------------------------------- */
    if( poSuperSeq != NULL )
    {
        for( v_i = poSuperSeq->var_begin(); 
             v_i != poSuperSeq->var_end(); 
             v_i++ )
            BuildFields( *v_i, NULL, NULL );
    }
}
예제 #12
0
int OGRDODSSequenceLayer::BuildFields( BaseType *poFieldVar, 
                                       const char *pszPathToVar,
                                       const char *pszPathToSequence )
    
{
    OGRFieldDefn oField( "", OFTInteger );

/* -------------------------------------------------------------------- */
/*      Setup field name, including path if non-local.                  */
/* -------------------------------------------------------------------- */
    if( pszPathToVar == NULL )
        oField.SetName( poFieldVar->name().c_str() );
    else
        oField.SetName( CPLSPrintf( "%s.%s", pszPathToVar, 
                                    poFieldVar->name().c_str() ) );
                                    
/* -------------------------------------------------------------------- */
/*      Capture this field definition.                                  */
/* -------------------------------------------------------------------- */
    switch( poFieldVar->type() )
    {
      case dods_byte_c:
      case dods_int16_c:
      case dods_uint16_c:
      case dods_int32_c:
      case dods_uint32_c:
        if( pszPathToSequence )
            oField.SetType( OFTIntegerList );
        else
            oField.SetType( OFTInteger );
        break;

      case dods_float32_c:
      case dods_float64_c:
        if( pszPathToSequence )
            oField.SetType( OFTRealList );
        else
            oField.SetType( OFTReal );
        break;

      case dods_str_c:
      case dods_url_c:
        if( pszPathToSequence )
            oField.SetType( OFTStringList );
        else
            oField.SetType( OFTString );
        break;

      case dods_sequence_c:
      {
          Sequence *seq = dynamic_cast<Sequence *>( poFieldVar );
          Sequence::Vars_iter v_i;

          // We don't support a 3rd level of sequence nesting.
          if( pszPathToSequence != NULL )
              return FALSE;

          // We don't explore down into the target sequence if we
          // are recursing from a supersequence. 
          if( poFieldVar == this->poTargetVar )
              return FALSE;

          for( v_i = seq->var_begin(); v_i != seq->var_end(); v_i++ )
          {
              BuildFields( *v_i, oField.GetNameRef(), oField.GetNameRef() );
          }
      }
      return FALSE;

      default:
        return FALSE;
    }

/* -------------------------------------------------------------------- */
/*      Add field to feature defn, and capture mapping.                 */
/* -------------------------------------------------------------------- */
    poFeatureDefn->AddFieldDefn( &oField );

    papoFields = (OGRDODSFieldDefn **) 
        CPLRealloc( papoFields, sizeof(void*) * poFeatureDefn->GetFieldCount());

    papoFields[poFeatureDefn->GetFieldCount()-1] = 
        new OGRDODSFieldDefn();

    papoFields[poFeatureDefn->GetFieldCount()-1]->Initialize(
        OGRDODSGetVarPath(poFieldVar).c_str(), "dds", 
        poTargetVar, poSuperSeq );

    
    if( pszPathToSequence )
        papoFields[poFeatureDefn->GetFieldCount()-1]->pszPathToSequence 
            = CPLStrdup( pszPathToSequence );

    return TRUE;
}
예제 #13
0
bool TRoss::LoadOnlyConstants(const char* _RossPath)
{
	strcpy  (RossPath, _RossPath);
	if(!MakePath (RossPath, "config.txt", ConfigFile) )		
	{
		 m_LastError = "cannot find config.txt";
		 return false; 
	};

	if(!MakePath (RossPath, "DomItems.txt", DomItemsTextFile) )		
	{
		 m_LastError = "cannot find DomItems.txt";
		 return false; 
	};
	
	if(!MakePath (RossPath, "Items.txt", ItemsFile) )		
	{
		 m_LastError = "cannot find Items.txt";
		 return false; 
	};
	

	if(!MakePath (RossPath, "Domens.txt", DomensFile) )
	{
		 m_LastError = "cannot find Domens.txt";
		 return false; 
	};
	if(!MakePath (RossPath, "Fields.txt", FieldsFile))
	{
		 m_LastError = "cannot find Fields.txt";
		 return false; 
	};

	if (!ReadConfig())
	{
		m_LastError = " Cannot parse config ";
		return false;
	};

	{
		char LastReadLine[1000];
		if(!BuildDomens (LastReadLine) )
		{
			m_LastError = Format (" Cannot build domens: the last read line=%s",LastReadLine);
			return false;
		}
	};

	if(!BuildDomItems ())  
	{	
        m_LastError = "Cannot build domitems";
        return false; 
    };

	if(!BuildFields (m_MaxNumDom))
	{
        return false; 
	};
	MakePath (RossPath, "Cortege.bin", CortegeFile);
	MakePath (RossPath, "Units.bin", UnitsFile);
 	MakePath (RossPath, "Comments.bin", UnitCommentsFile);

	return true;
};
예제 #14
0
OGRFeature *OGRMySQLTableLayer::GetFeature( GIntBig nFeatureId )

{
    if( pszFIDColumn == NULL )
        return OGRMySQLLayer::GetFeature( nFeatureId );

/* -------------------------------------------------------------------- */
/*      Discard any existing resultset.                                 */
/* -------------------------------------------------------------------- */
    ResetReading();

/* -------------------------------------------------------------------- */
/*      Prepare query command that will just fetch the one record of    */
/*      interest.                                                       */
/* -------------------------------------------------------------------- */
    char        *pszFieldList = BuildFields();
    CPLString    osCommand;

    osCommand.Printf(
             "SELECT %s FROM `%s` WHERE `%s` = " CPL_FRMT_GIB,
             pszFieldList, poFeatureDefn->GetName(), pszFIDColumn,
             nFeatureId );
    CPLFree( pszFieldList );

/* -------------------------------------------------------------------- */
/*      Issue the command.                                              */
/* -------------------------------------------------------------------- */
    if( mysql_query( poDS->GetConn(), osCommand ) )
    {
        poDS->ReportError( osCommand );
        return NULL;
    }

    hResultSet = mysql_store_result( poDS->GetConn() );
    if( hResultSet == NULL )
    {
        poDS->ReportError( "mysql_store_result() failed on query." );
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Fetch the result record.                                        */
/* -------------------------------------------------------------------- */
    char **papszRow;
    unsigned long *panLengths;

    papszRow = mysql_fetch_row( hResultSet );
    if( papszRow == NULL )
        return NULL;

    panLengths = mysql_fetch_lengths( hResultSet );

/* -------------------------------------------------------------------- */
/*      Transform into a feature.                                       */
/* -------------------------------------------------------------------- */
    iNextShapeId = nFeatureId;

    OGRFeature *poFeature = RecordToFeature( papszRow, panLengths );

    iNextShapeId = 0;

/* -------------------------------------------------------------------- */
/*      Cleanup                                                         */
/* -------------------------------------------------------------------- */
    if( hResultSet != NULL )
        mysql_free_result( hResultSet );
 		hResultSet = NULL;

    return poFeature;
}