FdoPtr<FdoSmPhRdClassReader> FdoSmPhOdbcMgr::CreateRdClassReader( FdoPtr<FdoSmPhRowCollection> rows, FdoStringP schemaName, FdoStringP className, FdoBoolean keyedOnly, FdoStringP database, FdoStringP owner ) { rdbi_vndr_info_def info; rdbi_vndr_info(GetRdbiContext(), &info ); #pragma message ("TODO: look up schema object to get owner name") // Ideally, we would not exclude based on RdSchemaPrefix, but rather // look up an approprate owner name, based on schemaName, or adjust the calling // code to pass in the right owner name -- which may be an empty string // on data sources that do not support named physical schemas. // // For SQL Server sources, there could be a physical schema called "Fdo" so don't // treat it specially, use it as the owner name. if (schemaName != NULL && schemaName.GetLength() > 0 && (info.dbversion == RDBI_DBVERSION_ODBC_SQLSERVER || schemaName != this->RdSchemaPrefix) && (owner == NULL || owner.GetLength() <= 0) ) { owner = schemaName; } return FdoSmPhMgr::CreateRdClassReader(rows, schemaName, className, keyedOnly, database, owner); }
void FdoSmLpGrdDataPropertyDefinition::Update( FdoPhysicalPropertyMapping* pPropOverrides ) { FdoSmPhMgrP pPhysical = GetLogicalPhysicalSchema()->GetPhysicalSchema(); FdoRdbmsOvDataPropertyDefinition* pDataPropOverrides = dynamic_cast<FdoRdbmsOvDataPropertyDefinition*>(pPropOverrides); // Error if the overrides are not for a data property if ( pPropOverrides && !pDataPropOverrides ) AddWrongOverrideTypeError(); FdoStringP ovColName; if ( pDataPropOverrides ) { // Get the column name from the physical overrides, if specified. FdoRdbmsOvColumnP columnOverrides = pDataPropOverrides->GetColumn(); if ( columnOverrides ) { SetIsFixedColumn( true ); if ( wcslen(columnOverrides->GetName()) > 0 ) ovColName = columnOverrides->GetName(); } } if ( (ovColName == L"") && (GetElementState() == FdoSchemaElementState_Unchanged) && GetIsFromFdo() ) { // Always make column name fixed when this object is from an FDO config document. // In this case this property must attach to an existing column so must // prevent the column name from being mangled. // Property always attaches to a column in the providers neutral case. // An explicit override must be supplied to attach to column whose // name is of another case. ovColName =GetName(); SetIsFixedColumn( true ); } if ( (!RefBaseProperty()) && ((GetElementState() == FdoSchemaElementState_Added) || GetIsFromFdo()) ) { // Set column name from override when property is not inherited and it is // new or from a config doc. if ( ovColName.GetLength() > 0 ) { // For foreign columns, root column is always the one // specified in the overrides. if ( ColumnIsForeign() ) SetRootColumnName( ovColName ); SetColumnName( ovColName ); } } else if ( GetElementState() == FdoSchemaElementState_Modified ) { if ( (ovColName.GetLength() > 0) && (ovColName.ICompare(Get_ColumnName()) != 0) ) AddColNameChangeError( ovColName ); } }
void FdoSmLpGrdPropertyMappingSingle::SetupOverrides( const FdoSmLpPropertyMappingSingle* pBase, FdoSmLpObjectPropertyDefinition* pParent, FdoRdbmsOvPropertyMappingSingle* pOverrides, bool bInherit ) { FdoSmPhMgrP mgr = GetLogicalPhysicalSchema()->GetPhysicalSchema(); FdoStringP prefix = GetPrefix(); // Extract the physical overrides. if ( pOverrides ) { prefix = pOverrides->GetPrefix(); if ( prefix.GetLength() > 0 ) { if ( prefix != mgr->CensorDbObjectName(prefix) ) AddPrefixCharError(prefix); if ( prefix.GetLength() > mgr->DbObjectNameMaxLen() ) AddPrefixLengthError(prefix, mgr->DbObjectNameMaxLen()); } } if ( prefix.GetLength() == 0 ) { if ( pBase ) { // Get them from base definition if this one is copied or inherited. prefix = pBase->GetPrefix(); } // Generate default column prefix from object property name. if ( prefix.GetLength() == 0 ) { prefix = mgr->CensorDbObjectName(pParent->GetName()).Mid(0,25); } if ( (pParent->GetElementState() == FdoSchemaElementState_Added) && !bInherit ) { FdoSmLpObjectPropertyClass* pParentClass = dynamic_cast<FdoSmLpObjectPropertyClass*>( (FdoSmLpSchemaElement*)(pParent->GetParent()) ); // Pre-pend base property prefix to keep prefix as unique as possible. if ( pParentClass ) { const FdoSmLpPropertyMappingSingle* pParentMapping = FdoSmLpGrdPropertyMappingSingle::Cast( pParentClass->RefObjectProperty()->RefMappingDefinition() ); if ( pParentMapping ) { prefix = FdoStringP(pParentMapping->GetPrefix()) + L"_" + prefix; } } } } SetPrefix( prefix ); }
FdoExpressionEngineFunctionCollection* FdoRdbmsSelectCommand::GetUserDefinedFunctions( FdoSmLpSpatialContextCollection *scColl, FdoClassDefinition *classDef ) { // Length2D and Area2D require to pass in the 'geodetic' flag. // Check the associated coordinate system. In case it is geodetic, create a custom function. FdoPtr<FdoExpressionEngineFunctionCollection> userDefinedFunctions; if (classDef->GetClassType() == FdoClassType_FeatureClass) { FdoPtr<FdoGeometricPropertyDefinition> gpd = ((FdoFeatureClass*)classDef)->GetGeometryProperty(); if ( gpd ) { FdoStringP scname = gpd->GetSpatialContextAssociation(); if ( scname.GetLength() != 0 ) { FdoSmLpSpatialContextP sc = scColl->FindItem( scname ); FdoStringP wkt = sc->GetCoordinateSystemWkt(); if ( wkt.Contains( L"PROJCS" ) ) ; // do nothing else if ( wkt.Contains( L"GEOGCS" ) ) { userDefinedFunctions = FdoExpressionEngineFunctionCollection::Create(); userDefinedFunctions->Add( FdoFunctionLength2D::Create(true)); userDefinedFunctions->Add( FdoFunctionArea2D::Create(true)); } } } } return FDO_SAFE_ADDREF(userDefinedFunctions.p); }
FdoDateTime FdoXmlFeatureReaderImpl::GetDateTime(FdoString* propertyName) { FdoStringP value = GetString (propertyName); if (value.GetLength () == 0) { return FdoDateTime (0, 0, 0, 0, 0, 0); } FdoPtr<FdoDateTimeValue> dt; // let's try DATE first FdoStringP date = FdoStringP(L"DATE '") + value + L"'"; try { dt = static_cast<FdoDateTimeValue *> (FdoDateTimeValue::Parse (date)); } catch (FdoException* e) { e->Release(); // oops, it's not a date, try TIMESTAMP FdoStringP timestamp = FdoStringP(L"TIMESTAMP '") + value + L"'"; try { dt = static_cast<FdoDateTimeValue *> (FdoDateTimeValue::Parse (timestamp)); } catch (FdoException* e1) { e1->Release(); // failed again, try the last option: TIME, this time, do not catch any exception FdoStringP time = FdoStringP(L"TIME '") + value + L"'"; dt = static_cast<FdoDateTimeValue *> (FdoDateTimeValue::Parse (time)); } } return dt->GetDateTime (); }
FdoStringP FdoSmPhRdPostGisColumnReader::GetString( FdoStringP tableName, FdoStringP fieldName ) { FdoStringP fieldValue; if ( fieldName == L"default_value" ) { FdoStringP defValue = FdoSmPhRdColumnReader::GetString( tableName, fieldName ); // '2001-10-01 00:00:00'::timestamp without time zone if( defValue != NULL && defValue.GetLength() != 0 ) { if ( GetType() == FdoSmPhColType_Date ) { // reformat the string to the Fdo expected DateTime default format fieldValue = defValue = defValue.Left(L"::"); if( fieldValue != NULL && fieldValue.GetLength() != 0 ) fieldValue = FdoStringP(L"TIMESTAMP ") + defValue; else fieldValue = L""; } else { // Remove any type casting at the end of the default value. FdoString* defPtr = (FdoString*) defValue; for ( int i = (wcslen(defPtr) - 1); i > 0; i-- ) { // Don't remove anything inside brackets or quote delimiters if ( (defPtr[i] == ')')|| (defPtr[i] == '\'') ) break; // type casting part starts with :: if ( wcsncmp(&defPtr[i], L"::", 2) == 0 ) { defValue = defValue.Mid(0,i); break; } } fieldValue = defValue; } } } else if ( fieldName == L"size" ) { fieldValue = FdoStringP::Format( L"%d", mSize ); } else if ( fieldName == L"scale" ) { fieldValue = FdoStringP::Format( L"%d", mScale ); } else { fieldValue = FdoSmPhRdColumnReader::GetString( tableName, fieldName ); } return fieldValue; }
void OdbcConnectionUtil::CleanFiles(FdoStringCollection* files, FdoStringP& pTypeName) { try { FdoString* pTypeNamecst = pTypeName; size_t lng = pTypeName.GetLength(); size_t count = files->GetCount(); for (size_t i = 0; i < count; i++) { FdoStringP name = files->GetString(i); if (lng != name.GetLength()) { if (name.Contains(pTypeName)) FdoCommonFile::Delete (name, true); } } } catch(...){} }
int GWSQualifiedName::ToString (wchar_t * res, int len) const { size_t retlen = 0; if (res != NULL) { FdoStringP str; str = m_schema; str += L":"; str += m_name; retlen = gws_min(str.GetLength (), (size_t)len); wcsncpy (res, str, retlen); if ((int)retlen < len) * (res + retlen) = 0; } return (int)retlen; }
FdoStringP FdoXslTransformerXalan::XalanNodeToUnicode(const XALAN_CPP_NAMESPACE::XalanNode* inNode) { FdoStringP serializedNode; const XALAN_CPP_NAMESPACE::XalanNode* node = inNode; while (node != NULL) { serializedNode = FdoStringP::Format( L"%ls%ls%ls", //WITH INDEX: L"%ls[%d]%ls%ls", (FdoString*)XalanDomStringToUnicode(node->getNodeName()), //node->getIndex(), serializedNode.GetLength() > 0 ? L"/" : L"", (FdoString*)serializedNode); node = node->getParentNode(); } return serializedNode; }
FdoStringP FdoSmPhOdbcMgr::FormatSQLVal( FdoStringP value, FdoSmPhColType valueType ) { FdoStringP sqlString; if ( value.GetLength() > 0 ) { if ( valueType == FdoSmPhColType_String || valueType == FdoSmPhColType_Date ) sqlString = FdoStringP(L"'") + FdoStringP(value).Replace( L"'", L"''" ) + FdoStringP(L"'"); else sqlString = value; } else { sqlString = L"null"; } return sqlString; }
void FdoXmlElementMapping::_writeXml( FdoXmlWriter* xmlWriter, const FdoXmlFlags* flags ) { xmlWriter->WriteStartElement( L"element" ); FdoPhysicalElementMapping::_writeXml( xmlWriter, flags ); // Encode names to handle characters not allowed in XML names. FdoStringP classSchema = flags->GetNameAdjust() ? ((FdoString*) xmlWriter->EncodeName(GetSchemaName())) : GetSchemaName(); xmlWriter->WriteAttribute( L"classSchema", classSchema ); // Encode names to handle characters not allowed in XML names. FdoStringP className = flags->GetNameAdjust() ? ((FdoString*) xmlWriter->EncodeName(GetClassName())) : GetClassName(); // TODO: centralize // Complex Type name is class name with "Type" suffix appended. if ( className.GetLength() > 0 ) { className += "Type"; } xmlWriter->WriteAttribute( L"className", className ); if ( mGmlUri != L"" ) { xmlWriter->WriteAttribute( L"gmlUri", mGmlUri ); } if ( mGmlLocalName != L"" ) { xmlWriter->WriteAttribute( L"gmlLocalName", mGmlLocalName ); } xmlWriter->WriteEndElement(); }
FdoSmPhRowP FdoSmPhRdMySqlOwnerReader::MakeBinds( FdoSmPhMgrP mgr, FdoStringP ownerName ) { FdoSmPhRowP row = new FdoSmPhRow( mgr, L"Binds" ); FdoSmPhDbObjectP rowObj = row->GetDbObject(); if ( ownerName.GetLength() > 0 ) { FdoSmPhFieldP field = new FdoSmPhField( row, L"owner_name", rowObj->CreateColumnDbObject(L"owner_name",false) ); field->SetFieldValue(ownerName); } return( row ); }
FdoSmPhOwnerP FdoSmPhSqsDatabase::NewOwner( FdoStringP owner, bool hasMetaSchema, FdoSchemaElementState elementState, FdoSmPhRdOwnerReader* /*reader*/ ) { FdoStringP SqsSchemaName = GetManager()->GetDefaultOwnerName(); return new FdoSmPhSqsOwner( owner.GetLength() > 0 ? owner : SqsSchemaName, hasMetaSchema, this, elementState ); }
FdoStringP FdoSmPhRdSqsConstraintReader::GetString( FdoStringP tableName, FdoStringP fieldName ) { FdoStringP fieldValue; if ( fieldName == L"table_name" ) { FdoStringP dbObjectName = FdoSmPhRdConstraintReader::GetString( tableName, fieldName ); FdoStringP userName = FdoSmPhRdConstraintReader::GetString( tableName, L"table_schema" ); fieldValue = userName + L"." + dbObjectName; } else if ( fieldName == L"check_clause" ) { fieldValue = FdoSmPhRdConstraintReader::GetString( tableName, fieldName ); // check clause completely fills the buffer allocated by GDBI so it may have // been truncated. If so, skip it since truncation gives it invalid syntax. if ( fieldValue.GetLength() >= ODBCDR_WLONGVARCHAR_SIZE ) fieldValue = L""; } else { fieldValue = FdoSmPhRdConstraintReader::GetString( tableName, fieldName ); } return fieldValue; }
FdoSmPhReaderP FdoSmPhRdMySqlOwnerReader::MakeQueryReader( FdoSmPhDatabaseP database, FdoStringP ownerName ) { bool owner_set = true; FdoStringP sqlString; FdoSmPhMgrP mgr = database->GetManager(); FdoSmPhMySqlMgr* pMgr = (FdoSmPhMySqlMgr*)(FdoSmPhMgr*)mgr; if (ownerName.GetLength() == 0 ) owner_set = false; FdoSmPhReaderP reader; //TODO: cache the queries for performance /* if ( object_set ) reader = pMgr->GetOwnerReader(dblink_set); else reader = pMgr->GetOwnersReader(dblink_set); */ // TODO: create constant for F_SCHEMAINFO if ( !reader ) { // Generate sql statement if not already done // information_schema tables use the utf8 character set with a // case-insensitive collation. This causes problems with MySQL instances // on Linux, where database and table names are case-sensitive. // The following query overrides the collations to utf8_bin, which // is case-sensitive. sqlString = FdoStringP::Format( L"select schema_name as name, \n" L" default_character_set_name \n" L" from information_schema.schemata S\n" L" %ls\n" L" order by schema_name asc", owner_set ? L"where S.schema_name collate utf8_bin = ?" : L"" ); FdoSmPhRowsP rows = MakeRows( mgr ); FdoSmPhRowP row = rows->GetItem(0); FdoSmPhFieldP field = new FdoSmPhField( row, L"default_character_set_name", row->CreateColumnInt64(L"default_character_set_name",false) ); reader = new FdoSmPhRdGrdQueryReader(row, sqlString, mgr, MakeBinds(mgr,ownerName) ); /* if ( object_set ) pMgr->SetOwnerReader(reader, dblink_set); else pMgr->SetOwnersReader(reader, dblink_set); */ } else { // Re-executing so update bind variables first. FdoSmPhRdGrdQueryReader* pReader = (FdoSmPhRdGrdQueryReader*)(FdoSmPhReader*) reader; FdoSmPhRowP binds = pReader->GetBinds(); FdoSmPhFieldsP fields = binds->GetFields(); if ( owner_set ) FdoSmPhFieldP(fields->GetItem(L"owner_name"))->SetFieldValue(ownerName); pReader->Execute(); } return reader; }
void OdbcConnectionUtil::LoadInitializeFile() { try { m_SetupDone = true; FdoStringP fileNameCfg = getenv("initfiletest"); if (fileNameCfg.GetLength() == 0) fileNameCfg = ODBC_INIT_FILENAME_TEST; else FdoCommonOSUtil::setenv("initfiletest", ""); char buffer[1001]; FdoCommonFile pFile; FdoCommonFile::ErrorCode err = FdoCommonFile::ERROR_NONE; if (!pFile.OpenFile(fileNameCfg, FdoCommonFile::IDF_OPEN_READ, err) ) { printf( "WARNING: OdbcConnectionUtil->LoadInitializeFile failed to open file '%s'\n", (const char*)fileNameCfg ); fileNameCfg = ODBC_INIT_FILENAME_TEST; if (!pFile.OpenFile(fileNameCfg, FdoCommonFile::IDF_OPEN_READ, err) ) { printf( "WARNING: OdbcConnectionUtil->LoadInitializeFile failed to open file '%s'\n", (const char*)fileNameCfg ); printf( "Default values will be used\n" ); } } if ( FdoCommonFile::ERROR_NONE == err ) { long bytesRead = 0; pFile.ReadFile( buffer, 1000, &bytesRead); buffer[bytesRead] = '\0'; pFile.CloseFile(); m_SetupValues->ParseStringProperties((FdoStringP)buffer); } m_SetupValues->SetProperty(L"provider", L"Odbc"); // Setup default values in case are missing // MySql if (!m_SetupValues->PropertyExist( L"serviceMySql" )) m_SetupValues->SetProperty( L"serviceMySql", ODBCMYSQL_SERVICENAME_DEFAULT); if (!m_SetupValues->PropertyExist( L"usernameMySql" )) m_SetupValues->SetProperty( L"usernameMySql", ODBCMYSQL_USERNAME_DEFAULT); if (!m_SetupValues->PropertyExist( L"passwordMySql" )) m_SetupValues->SetProperty( L"passwordMySql", ODBCMYSQL_PASSWORD_DEFAULT); if (!m_SetupValues->PropertyExist( L"DSNMySql" )) m_SetupValues->SetProperty( L"DSNMySql", ODBCMYSQL_DSN_DEFAULT); // SqlServer if (!m_SetupValues->PropertyExist( L"serviceSqlServer" )) m_SetupValues->SetProperty( L"serviceSqlServer", ODBCSQLSERVER_SERVICENAME_DEFAULT); if (!m_SetupValues->PropertyExist( L"usernameSqlServer" )) { char uname[1024]; int size=1024; UnitTestUtil::GetRealUserName(uname, size); m_SetupValues->SetProperty( L"usernameSqlServer", (FdoStringP)uname); } if (!m_SetupValues->PropertyExist( L"passwordSqlServer" )) m_SetupValues->SetProperty( L"passwordSqlServer", ODBCSQLSERVER_PASSWORD_DEFAULT); if (!m_SetupValues->PropertyExist( L"DSNSqlServer" )) m_SetupValues->SetProperty( L"DSNSqlServer", ODBCSQLSERVER_DSN_DEFAULT); // Oracle if (!m_SetupValues->PropertyExist( L"serviceOracle" )) m_SetupValues->SetProperty( L"serviceOracle", ODBCORACLE_SERVICENAME_DEFAULT); if (!m_SetupValues->PropertyExist( L"usernameOracle" )) { char uname[1024]; int size=1024; UnitTestUtil::GetRealUserName(uname, size); m_SetupValues->SetProperty( L"usernameOracle", (FdoStringP)uname); } if (!m_SetupValues->PropertyExist( L"passwordOracle" )) m_SetupValues->SetProperty( L"passwordOracle", ODBCORACLE_PASSWORD_DEFAULT); if (!m_SetupValues->PropertyExist( L"DSNOracle" )) m_SetupValues->SetProperty( L"DSNOracle", ODBCORACLE_DSN_DEFAULT); if (!m_SetupValues->PropertyExist( L"enableOracleSetup" )) m_SetupValues->SetProperty( L"enableOracleSetup", L"true"); // Access if (!m_SetupValues->PropertyExist( L"DSNAccess" )) m_SetupValues->SetProperty( L"DSNAccess", ODBCACCESS_DSN_DEFAULT); if (m_SetupValues->PropertyExist( L"AccessDriverVersion" )) { FdoStringP strVersion = m_SetupValues->GetPropertyValue(L"AccessDriverVersion"); double dVersion = strVersion.ToDouble(); if (dVersion >= 12) ACCESS_ODBC_DRIVER_NAME = L"Microsoft Access Driver (*.mdb, *.accdb)"; } // dBASE if (!m_SetupValues->PropertyExist( L"DSNDbase" )) m_SetupValues->SetProperty( L"DSNDbase", ODBCDBASE_DSN_DEFAULT); if (m_SetupValues->PropertyExist( L"DbaseDriverVersion" )) { FdoStringP strVersion = m_SetupValues->GetPropertyValue(L"DbaseDriverVersion"); double dVersion = strVersion.ToDouble(); if (dVersion >= 12) DBASE_ODBC_DRIVER_NAME = L"Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)"; } // Excel if (!m_SetupValues->PropertyExist( L"DSNExcel" )) m_SetupValues->SetProperty( L"DSNExcel", ODBCEXCEL_DSN_DEFAULT); if (m_SetupValues->PropertyExist( L"ExcelDriverVersion" )) { FdoStringP strVersion = m_SetupValues->GetPropertyValue(L"ExcelDriverVersion"); double dVersion = strVersion.ToDouble(); if (dVersion >= 12) EXCEL_ODBC_DRIVER_NAME = L"Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)"; } // Text if (!m_SetupValues->PropertyExist( L"DSNText" )) m_SetupValues->SetProperty( L"DSNText", ODBCTEXT_DSN_DEFAULT); if (m_SetupValues->PropertyExist( L"TextDriverVersion" )) { FdoStringP strVersion = m_SetupValues->GetPropertyValue(L"TextDriverVersion"); double dVersion = strVersion.ToDouble(); if (dVersion >= 12) TEXT_ODBC_DRIVER_NAME = L"Microsoft Access Text Driver (*.txt, *.csv)"; } if (!m_SetupValues->PropertyExist( L"clean" )) m_SetupValues->SetProperty( L"clean", L"true"); } catch(...){} }