static void IIdemo_init() { IIAPI_INITPARM initParm; printf( "IIdemo_init: initializing API\n" ); initParm.in_version = IIAPI_VERSION_1; initParm.in_timeout = -1; IIapi_initialize( &initParm ); return; }
static void IIdemo_init( II_PTR *envHandle ) { IIAPI_INITPARM initParm; printf( "IIdemo_init: initializing API\n" ); initParm.in_version = IIAPI_VERSION_2; initParm.in_timeout = -1; IIapi_initialize( &initParm ); *envHandle = initParm.in_envHandle; return; }
int OGRIngresDataSource::Open( const char *pszFullName, char **papszOptions, int bUpdate ) { CPLAssert( nLayers == 0 ); #define MAX_TARGET_STRING_LENGTH 512 char pszDBTarget[MAX_TARGET_STRING_LENGTH]; /* -------------------------------------------------------------------- */ /* Verify we have a dbname, this parameter is required. */ /* -------------------------------------------------------------------- */ const char *pszDBName = CSLFetchNameValue(papszOptions,"dbname"); if( pszDBName == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "No DBNAME item provided in INGRES datasource name." ); return FALSE; } /* -------------------------------------------------------------------- */ /* Do we have a table list? */ /* -------------------------------------------------------------------- */ char **papszTableNames = NULL; const char *pszTables = CSLFetchNameValue(papszOptions,"tables"); if( pszTables != NULL ) papszTableNames = CSLTokenizeStringComplex(pszTables,"/",TRUE,FALSE); /* -------------------------------------------------------------------- */ /* Add support to dynamic vnode if passed */ /* -------------------------------------------------------------------- */ const char *pszHost = CSLFetchNameValue(papszOptions,"host"); if (pszHost) { const char *pszInstance = CSLFetchNameValue(papszOptions,"instance"); if (pszInstance == NULL || strlen(pszInstance) != 2) { CPLError( CE_Failure, CPLE_OpenFailed, "instance name must be specified with host." ); return FALSE; } /* ** make sure the user name and password are passed too, ** note it could not be zero length. */ const char *pszUsername = CSLFetchNameValue(papszOptions,"username"); const char *pszPassword = CSLFetchNameValue(papszOptions,"password"); if (pszUsername == NULL || strlen(pszUsername) == 0) { CPLError( CE_Failure, CPLE_OpenFailed, "user name must be specified in dynamic vnode." ); return FALSE; } if (pszPassword == NULL || strlen(pszPassword) == 0) { CPLError( CE_Failure, CPLE_OpenFailed, "password must be specified in dynamic vnode." ); return FALSE; } /* ** construct the vnode string, like : ** @host,protocol,port[;attribute=value{;attribute=value}][[user,password]], ** visit for detail ** http://docs.actian.com/ingres/10.0/command-reference-guide/1207-dynamic-vnode-specificationconnect-to-remote-node */ sprintf(pszDBTarget, "@%s,%s,%s;%s[%s,%s]::%s ", pszHost, /* host, compute name or IP address */ "TCP_IP", /* protocal, default with TCP/IP */ pszInstance, /* instance Name */ "" , /* option, Null */ pszUsername, /* user name, could not be empty */ pszPassword, /* pwd */ pszDBName /* database name */ ); CPLDebug("INGRES", pszDBTarget); } else { /* Remain the database name */ strcpy(pszDBTarget, pszDBName); } /* -------------------------------------------------------------------- */ /* Initialize the Ingres API. Should we only do this once per */ /* program run? Really we should also try to terminate the api */ /* on program exit. */ /* -------------------------------------------------------------------- */ IIAPI_INITPARM initParm; initParm.in_version = IIAPI_VERSION_1; initParm.in_timeout = -1; IIapi_initialize( &initParm ); /* -------------------------------------------------------------------- */ /* check effective user and db password */ /* -------------------------------------------------------------------- */ hConn = NULL; const char *pszEffuser = CSLFetchNameValue(papszOptions,"effuser"); const char *pszDBpwd = CSLFetchNameValue(papszOptions,"dbpwd"); if ( pszEffuser && strlen(pszEffuser) > 0 && pszDBpwd && strlen(pszDBpwd) > 0 ) { if (SetConnParam(&hConn, IIAPI_CP_EFFECTIVE_USER, (II_PTR)pszEffuser) != IIAPI_ST_SUCCESS || SetConnParam(&hConn, IIAPI_CP_DBMS_PASSWORD, (II_PTR)pszDBpwd) != IIAPI_ST_SUCCESS ) { return FALSE; } } /* -------------------------------------------------------------------- */ /* Try to connect to the database. */ /* -------------------------------------------------------------------- */ IIAPI_CONNPARM connParm; IIAPI_WAITPARM waitParm = { -1 }; memset( &connParm, 0, sizeof(connParm) ); connParm.co_genParm.gp_callback = NULL; connParm.co_genParm.gp_closure = NULL; connParm.co_target = (II_CHAR *) pszDBTarget; connParm.co_connHandle = hConn; connParm.co_tranHandle = NULL; connParm.co_username = (II_CHAR*) CSLFetchNameValue(papszOptions,"username"); connParm.co_password = (II_CHAR*)CSLFetchNameValue(papszOptions,"password"); connParm.co_timeout = -1; if( CSLFetchNameValue(papszOptions,"timeout") != NULL ) connParm.co_timeout = atoi(CSLFetchNameValue(papszOptions,"timeout")); IIapi_connect( &connParm ); while( connParm.co_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); hConn = connParm.co_connHandle; if( connParm.co_genParm.gp_status != IIAPI_ST_SUCCESS || hConn == NULL ) { OGRIngresStatement::ReportError( &(connParm.co_genParm), "Failed to connect to Ingres database." ); return FALSE; } pszName = CPLStrdup( pszFullName ); bDSUpdate = bUpdate; // Check for new or old Ingres spatial library { OGRIngresStatement oStmt( hConn ); if( oStmt.ExecuteSQL("SELECT COUNT(*) FROM iicolumns WHERE table_name = 'iiattribute' AND column_name = 'attgeomtype'" ) ) { char **papszFields; while( (papszFields = oStmt.GetRow()) ) { CPLString osCount = papszFields[0]; if( osCount[0] == '0' ) { bNewIngres = FALSE; } else { bNewIngres = TRUE; } } } } /* -------------------------------------------------------------------- */ /* Get a list of available tables. */ /* -------------------------------------------------------------------- */ if( papszTableNames == NULL ) { OGRIngresStatement oStmt( hConn ); if( oStmt.ExecuteSQL( "select table_name from iitables where system_use = 'U' and table_name not like 'iietab_%'" ) ) { char **papszFields; while( (papszFields = oStmt.GetRow()) ) { CPLString osTableName = papszFields[0]; osTableName.Trim(); papszTableNames = CSLAddString( papszTableNames, osTableName ); } } } /* -------------------------------------------------------------------- */ /* Get the schema of the available tables. */ /* -------------------------------------------------------------------- */ int iRecord; for( iRecord = 0; papszTableNames != NULL && papszTableNames[iRecord] != NULL; iRecord++ ) { OpenTable( papszTableNames[iRecord], bUpdate ); } CSLDestroy( papszTableNames ); return TRUE; }
int main( int argc, char** argv ) { II_PTR envHandle = (II_PTR)NULL; IIAPI_INITPARM initParm; IIAPI_SETENVPRMPARM setEnvPrmParm; IIAPI_RELENVPARM relEnvParm; IIAPI_TERMPARM termParm; II_LONG longvalue; /* ** Initialize API at level 1 */ printf( "apisinit: initializing API at level 1 \n" ); initParm.in_version = IIAPI_VERSION_1; initParm.in_timeout = -1; IIapi_initialize( &initParm ); /* ** Terminate API */ printf( "apisinit: shutting down API\n" ); IIapi_terminate( &termParm ); /* ** Initialize API at level 2. Save environment handle. */ printf( "apisinit: initializing API at level 2 \n" ); initParm.in_version = IIAPI_VERSION_2; initParm.in_timeout = -1; IIapi_initialize( &initParm ); envHandle = initParm.in_envHandle; /* ** Set an environment parameter */ printf( "apisinit: set environment parameter\n" ); setEnvPrmParm.se_envHandle = envHandle; setEnvPrmParm.se_paramID = IIAPI_EP_DATE_FORMAT; setEnvPrmParm.se_paramValue = (II_PTR)&longvalue; longvalue = IIAPI_EPV_DFRMT_YMD; IIapi_setEnvParam( &setEnvPrmParm ); /* ** Release environment resources. */ printf( "apisinit: releasing environment handle\n" ); relEnvParm.re_envHandle = envHandle; IIapi_releaseEnv(&relEnvParm); /* ** Terminate API. */ printf( "apisinit: shutting down API\n" ); IIapi_terminate( &termParm ); return( 0 ); }
STATUS gcd_api_init( u_i2 api_ver, PTR *env ) { IIAPI_INITPARM init; IIAPI_SETENVPRMPARM set; bool done; STATUS status = OK; init.in_timeout = -1; init.in_version = api_ver; IIapi_initialize( &init ); if ( init.in_status != IIAPI_ST_SUCCESS && GCD_global.gcd_trace_level >= 1 ) TRdisplay( "%4d GCD Error initializing API: %s\n", -1, gcu_lookup( apiMap, init.in_status ) ); switch( init.in_status ) { case IIAPI_ST_SUCCESS : *env = init.in_envHandle; break; case IIAPI_ST_OUT_OF_MEMORY : status = E_GC4808_NO_MEMORY; break; default : status = E_GC4809_INTERNAL_ERROR; break; } for( done = (status != OK); ! done; done = TRUE ) { II_LONG value; set.se_envHandle = *env; set.se_paramID = IIAPI_EP_TRACE_FUNC; set.se_paramValue = (II_PTR)gcd_api_trace; IIapi_setEnvParam( &set ); if ( (status = set.se_status) != OK ) break; if( api_ver >= IIAPI_VERSION_6 ) { set.se_paramID = IIAPI_EP_DATE_ALIAS; set.se_paramValue = IIAPI_EPV_INGDATE; IIapi_setEnvParam( &set ); if ( (status = set.se_status) != OK ) break; } set.se_paramID = IIAPI_EP_DATE_FORMAT; value = IIAPI_EPV_DFRMT_FINNISH; set.se_paramValue = (II_PTR)&value; IIapi_setEnvParam( &set ); if ( (status = set.se_status) != OK ) break; set.se_paramID = IIAPI_EP_TIMEZONE; set.se_paramValue = "gmt"; IIapi_setEnvParam( &set ); if ( (status = set.se_status) != OK ) break; set.se_paramID = IIAPI_EP_MAX_SEGMENT_LEN; value = 8192; set.se_paramValue = (II_PTR)&value; IIapi_setEnvParam( &set ); if ( (status = set.se_status) != OK ) break; set.se_paramID = IIAPI_EP_DECIMAL_CHAR; set.se_paramValue = "."; IIapi_setEnvParam( &set ); if ( (status = set.se_status) != OK ) break; set.se_paramID = IIAPI_EP_MONEY_SIGN ; set.se_paramValue = "$"; IIapi_setEnvParam( &set ); if ( (status = set.se_status) != OK ) break; set.se_paramID = IIAPI_EP_MONEY_LORT ; value = IIAPI_EPV_MONEY_LEAD_SIGN; set.se_paramValue = (II_PTR)&value; IIapi_setEnvParam( &set ); if ( (status = set.se_status) != OK ) break; set.se_paramID = IIAPI_EP_MONEY_PRECISION ; value = 2; set.se_paramValue = (II_PTR)&value; IIapi_setEnvParam( &set ); if ( (status = set.se_status) != OK ) break; } if ( status != OK ) gcu_erlog( 0, GCD_global.language, status, NULL, 0, NULL ); return( status ); }
int OGRIngresDataSource::Open( const char *pszFullName, char **papszOptions, int bUpdate ) { CPLAssert( nLayers == 0 ); /* -------------------------------------------------------------------- */ /* Verify we have a dbname, this parameter is required. */ /* -------------------------------------------------------------------- */ const char *pszDBName = CSLFetchNameValue(papszOptions,"dbname"); if( pszDBName == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "No DBNAME item provided in INGRES datasource name." ); return FALSE; } /* -------------------------------------------------------------------- */ /* Do we have a table list? */ /* -------------------------------------------------------------------- */ char **papszTableNames = NULL; const char *pszTables = CSLFetchNameValue(papszOptions,"tables"); if( pszTables != NULL ) papszTableNames = CSLTokenizeStringComplex(pszTables,"/",TRUE,FALSE); /* -------------------------------------------------------------------- */ /* Initialize the Ingres API. Should we only do this once per */ /* program run? Really we should also try to terminate the api */ /* on program exit. */ /* -------------------------------------------------------------------- */ IIAPI_INITPARM initParm; initParm.in_version = IIAPI_VERSION_1; initParm.in_timeout = -1; IIapi_initialize( &initParm ); /* -------------------------------------------------------------------- */ /* Try to connect to the database. */ /* -------------------------------------------------------------------- */ IIAPI_CONNPARM connParm; IIAPI_WAITPARM waitParm = { -1 }; memset( &connParm, 0, sizeof(connParm) ); connParm.co_genParm.gp_callback = NULL; connParm.co_genParm.gp_closure = NULL; connParm.co_target = (II_CHAR *) pszDBName; connParm.co_connHandle = NULL; connParm.co_tranHandle = NULL; connParm.co_username = (II_CHAR*) CSLFetchNameValue(papszOptions,"username"); connParm.co_password = (II_CHAR*)CSLFetchNameValue(papszOptions,"password"); connParm.co_timeout = -1; if( CSLFetchNameValue(papszOptions,"timeout") != NULL ) connParm.co_timeout = atoi(CSLFetchNameValue(papszOptions,"timeout")); IIapi_connect( &connParm ); while( connParm.co_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); hConn = connParm.co_connHandle; if( connParm.co_genParm.gp_status != IIAPI_ST_SUCCESS || hConn == NULL ) { OGRIngresStatement::ReportError( &(connParm.co_genParm), "Failed to connect to Ingres database." ); return FALSE; } pszName = CPLStrdup( pszFullName ); bDSUpdate = bUpdate; // Check for new or old Ingres spatial library { OGRIngresStatement oStmt( hConn ); if( oStmt.ExecuteSQL("SELECT COUNT(*) FROM iicolumns WHERE table_name = 'iiattribute' AND column_name = 'attgeomtype'" ) ) { char **papszFields; while( (papszFields = oStmt.GetRow()) ) { CPLString osCount = papszFields[0]; if( osCount[0] == '0' ) { bNewIngres = FALSE; } else { bNewIngres = TRUE; } } } } /* -------------------------------------------------------------------- */ /* Get a list of available tables. */ /* -------------------------------------------------------------------- */ if( papszTableNames == NULL ) { OGRIngresStatement oStmt( hConn ); if( oStmt.ExecuteSQL( "select table_name from iitables where system_use = 'U' and table_name not like 'iietab_%'" ) ) { char **papszFields; while( (papszFields = oStmt.GetRow()) ) { CPLString osTableName = papszFields[0]; osTableName.Trim(); papszTableNames = CSLAddString( papszTableNames, osTableName ); } } } /* -------------------------------------------------------------------- */ /* Get the schema of the available tables. */ /* -------------------------------------------------------------------- */ int iRecord; for( iRecord = 0; papszTableNames != NULL && papszTableNames[iRecord] != NULL; iRecord++ ) { OpenTable( papszTableNames[iRecord], bUpdate ); } CSLDestroy( papszTableNames ); return TRUE; }