Changeset 14468

Show
Ignore:
Timestamp:
05/14/08 23:44:49 (2 months ago)
Author:
warmerdam
Message:

implement wrapped datasource name, add userid,password,tables,timeout support, add docs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/ogr/ogrsf_frmts/ingres/ogr_ingres.h

    r14313 r14468  
    253253    OGRErr              InitializeMetadataTables(); 
    254254 
    255     int                 Open( const char *, int bUpdate ); 
     255    int                 Open( const char *pszFullName,  
     256                              char **papszOptions, int bUpdate ); 
    256257    int                 OpenTable( const char *, int bUpdate ); 
    257258 
     
    286287class OGRIngresDriver : public OGRSFDriver 
    287288{ 
     289    char         **ParseWrappedName( const char * ); 
     290 
    288291  public: 
    289292                ~OGRIngresDriver(); 
  • trunk/gdal/ogr/ogrsf_frmts/ingres/ogringresdatasource.cpp

    r14313 r14468  
    8787/************************************************************************/ 
    8888 
    89 int OGRIngresDataSource::Open( const char * pszNewName, int bUpdate ) 
     89int OGRIngresDataSource::Open( const char *pszFullName,  
     90                               char **papszOptions, int bUpdate ) 
    9091 
    9192 
     
    9495 
    9596/* -------------------------------------------------------------------- */ 
    96 /*      Verify Ingres prefix.                                            */ 
    97 /* -------------------------------------------------------------------- */ 
    98     if( !EQUALN(pszNewName,"INGRES:",7) ) 
    99     { 
     97/*      Verify we have a dbname, this parameter is required.            */ 
     98/* -------------------------------------------------------------------- */ 
     99    const char *pszDBName = CSLFetchNameValue(papszOptions,"dbname"); 
     100 
     101    if( pszDBName == NULL ) 
     102    { 
     103        CPLError( CE_Failure, CPLE_OpenFailed, 
     104                  "No DBNAME item provided in INGRES datasource name." ); 
    100105        return FALSE; 
    101106    } 
    102107 
    103108/* -------------------------------------------------------------------- */ 
    104 /*      For now we assume the whole argument is the "dbname".           */ 
    105 /* -------------------------------------------------------------------- */ 
    106     const char *pszDBName = pszNewName + 7; 
     109/*      Do we have a table list?                                        */ 
     110/* -------------------------------------------------------------------- */ 
    107111    char **papszTableNames = NULL; 
    108  
     112    const char *pszTables = CSLFetchNameValue(papszOptions,"tables"); 
     113 
     114    if( pszTables != NULL ) 
     115        papszTableNames = CSLTokenizeStringComplex(pszTables,"/",TRUE,FALSE); 
     116     
    109117/* -------------------------------------------------------------------- */ 
    110118/*      Initialize the Ingres API. Should we only do this once per      */ 
     
    129137    connParm.co_connHandle = NULL; 
    130138    connParm.co_tranHandle = NULL; 
    131     connParm.co_username = NULL; 
    132     connParm.co_password = NULL; 
     139    connParm.co_username =  
     140        (II_CHAR*) CSLFetchNameValue(papszOptions,"username"); 
     141    connParm.co_password =  
     142        (II_CHAR*)CSLFetchNameValue(papszOptions,"password"); 
    133143    connParm.co_timeout = -1; 
     144 
     145    if( CSLFetchNameValue(papszOptions,"timeout") != NULL ) 
     146        connParm.co_timeout = atoi(CSLFetchNameValue(papszOptions,"timeout")); 
    134147 
    135148    IIapi_connect( &connParm ); 
     
    148161    } 
    149162 
    150     pszName = CPLStrdup( pszNewName ); 
     163    pszName = CPLStrdup( pszFullName ); 
    151164     
    152165    bDSUpdate = bUpdate; 
  • trunk/gdal/ogr/ogrsf_frmts/ingres/ogringresdriver.cpp

    r13622 r14468  
    5353 
    5454/************************************************************************/ 
     55/*                          ParseWrappedName()                          */ 
     56/************************************************************************/ 
     57 
     58char **OGRIngresDriver::ParseWrappedName( const char *pszEncodedName ) 
     59 
     60{ 
     61    if( pszEncodedName[0] != '@' ) 
     62        return NULL; 
     63 
     64    return CSLTokenizeStringComplex( pszEncodedName+1, ",", TRUE, FALSE ); 
     65} 
     66 
     67/************************************************************************/ 
    5568/*                                Open()                                */ 
    5669/************************************************************************/ 
     
    6073 
    6174{ 
    62     OGRIngresDataSource     *poDS; 
     75    OGRIngresDataSource     *poDS = NULL; 
     76    char **papszOptions = ParseWrappedName( pszFilename ); 
     77    const char *pszDriver; 
    6378 
    64     if( !EQUALN(pszFilename,"INGRES:",7) ) 
    65         return NULL; 
     79    pszDriver = CSLFetchNameValue( papszOptions, "driver" ); 
     80    if( pszDriver != NULL && EQUAL(pszDriver,"ingres") ) 
     81    { 
     82        poDS = new OGRIngresDataSource(); 
    6683 
    67     poDS = new OGRIngresDataSource(); 
     84        if( !poDS->Open( pszFilename, papszOptions, TRUE ) ) 
     85        { 
     86            delete poDS; 
     87            poDS = NULL; 
     88        } 
     89    } 
    6890 
    69     if( !poDS->Open( pszFilename, bUpdate ) ) 
    70     { 
    71         delete poDS; 
    72         return NULL; 
    73     } 
    74     else 
    75         return poDS; 
     91    CSLDestroy( papszOptions ); 
     92     
     93    return poDS; 
    7694} 
    7795 
     
    86104{ 
    87105    OGRIngresDataSource     *poDS; 
     106    char **papszOpenOptions; 
     107    const char *pszDriver; 
    88108 
    89     poDS = new OGRIngresDataSource(); 
     109    papszOpenOptions = ParseWrappedName( pszName ); 
    90110 
     111    pszDriver = CSLFetchNameValue( papszOpenOptions, "driver" ); 
    91112 
    92     if( !poDS->Open( pszName, TRUE ) ) 
     113    if( pszDriver != NULL && EQUAL(pszDriver,"ingres") ) 
    93114    { 
    94         delete poDS; 
    95         CPLError( CE_Failure, CPLE_AppDefined,  
    96                   "Ingres driver doesn't currently support database creation.\n" 
    97                   "Please create database before using." ); 
    98         return NULL; 
     115        poDS = new OGRIngresDataSource(); 
     116        if( !poDS->Open( pszName, papszOpenOptions, TRUE ) ) 
     117        { 
     118            delete poDS; 
     119            poDS = NULL; 
     120            CPLError( CE_Failure, CPLE_AppDefined,  
     121                      "Ingres driver doesn't currently support database creation.\n" 
     122                      "Please create database before using." ); 
     123        } 
    99124    } 
     125 
     126    CSLDestroy( papszOpenOptions ); 
    100127 
    101128    return poDS; 
  • trunk/gdal/ogr/ogrsf_frmts/ogr_formats.html

    r13960 r14468  
    107107</td></tr> 
    108108 
     109<tr><td> <a href="drv_ingres.html">INGRES</a> 
     110</td><td> INGRES 
     111</td><td> Yes 
     112</td><td> No 
     113</td></tr> 
     114 
    109115<tr><td> <a href="drv_kml.html">KML</a> 
    110116</td><td> KML