예제 #1
0
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);
}
예제 #2
0
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 ();
}
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);
}
FdoStringP FdoRdbmsMySqlFilterProcessor::GetGeometryColumnNameForProperty (
                            const FdoSmLpGeometricPropertyDefinition *pGeomProp,
                            bool                                      bChangeFilter)
{
	FdoStringP retVal;

    if (pGeomProp != NULL)
    {
	    retVal = pGeomProp->GetColumnName();

   		if (bChangeFilter) 
        {
            FdoStringP  tmpRetVal(retVal);

    	    FdoStringP suffixName = FdoStringP::Format(L"%ls",
		        	    (FdoString *) tmpRetVal.Mid( wcslen(retVal) - wcslen(NOTINDEXED_SUFFIX), wcslen(retVal)));

            // Strip the suffix from the column name
            if (suffixName.ICompare(NOTINDEXED_SUFFIX) == 0)
            {
                retVal = FdoStringP::Format(L"%ls", (FdoString *) tmpRetVal.Mid( 0, wcslen(retVal) - wcslen(NOTINDEXED_SUFFIX)));
            }
        }
	}

	return retVal;
}
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 );
}
예제 #7
0
FdoStringP FdoSmPhRdMySqlColumnReader::GetString( FdoStringP tableName, FdoStringP fieldName )
{

    if ( fieldName == L"size" ) {
        if ( GetString(L"", L"type_string") == L"bit" ) {
            FdoStringP fullType = GetString( L"", L"full_type" );
            FdoStringP bitSize = fullType.Right(L"(").Left(L")");
            
            return bitSize;
        }
    }

    return FdoSmPhRdColumnReader::GetString( tableName, fieldName );
}
예제 #8
0
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;
}
예제 #9
0
bool FdoSmPhPostGisOwner::IsDbObjectNameReserved( FdoStringP objectName )
{
    bool isReserved = FdoSmPhGrdOwner::IsDbObjectNameReserved( objectName );

    // The PostGIS DbObjectReader does not currently pick up indexes so
    // they are not cached in the owner's DbObject list and are thus not picked
    // up by base IsDbObjectNameReserved.

    // Do extra check against pg_class table to ensure objectName not currently
    // used by an index.

    if ( !isReserved ) {
        FdoStringP sqlString = FdoStringP::Format(
            L"select 1 from pg_catalog.pg_class C, pg_catalog.pg_namespace N "
            L"where C.relnamespace = N.oid and upper(N.nspname || '.' || C.relname) = %ls", 
            (FdoString*) GetManager()->FormatSQLVal(objectName.Upper(), FdoSmPhColType_String)
        );

        FdoSmPhRowP row = new FdoSmPhRow( GetManager(), L"GetObjectExists" );

        FdoSmPhRdQueryReaderP reader = GetManager()->CreateQueryReader( row, sqlString );

        isReserved = reader->ReadNext();
    }

    return isReserved;
}
예제 #10
0
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;
}
예제 #11
0
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();
}
예제 #12
0
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(...){}
}
예제 #13
0
FdoStringP FdoSmPhOdbcView::GetRootNameSql()
{
    FdoStringP rootDatabase = this->GetRootDatabase();
    FdoStringP rootOwner = this->GetRootOwner();
    FdoStringP rootObject = this->GetRootObjectName();

    if ( rootDatabase != L"" ) 
        // TODO: proper message indicating that Odbc provider does not
        // support multiple database instances.
        throw FdoSchemaException::Create();

    if ( (rootOwner == L"") || (rootOwner.ICompare(GetManager()->GetDefaultOwnerName()) == 0) ) 
        return rootObject;
    else 
        return FdoStringP::Format(
            L"%ls.dbo.%ls",
            (FdoString*) rootOwner,
            (FdoString*) rootObject
        );
}
예제 #14
0
FdoSmPhRdSqsConstraintReader::FdoSmPhRdSqsConstraintReader(
    FdoSmPhOwnerP owner,
	FdoStringsP tableNames,
    FdoStringP constraintType
) :
    FdoSmPhRdConstraintReader(),
    mConstraintName(constraintType.Upper()),
    mOwner(owner)
{
    SetSubReader(
        MakeReader(owner,tableNames,(FdoSmPhRdTableJoin*) NULL,constraintType)
    );
}
예제 #15
0
FdoSmPhRdSqsConstraintReader::FdoSmPhRdSqsConstraintReader(
    FdoSmPhOwnerP owner,
    FdoSmPhRdTableJoinP join,
    FdoStringP constraintType
) :
    FdoSmPhRdConstraintReader(),
    mConstraintName(constraintType.Upper()),
    mOwner(owner)
{
    SetSubReader(
        MakeReader(owner,DbObjectName2Objects(L""),join,constraintType)
    );
}
예제 #16
0
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;
}
예제 #17
0
FdoSmPhRdSqsConstraintReader::FdoSmPhRdSqsConstraintReader(
    FdoSmPhOwnerP owner,
	FdoStringP tableName,
    FdoStringP constraintType
) :
    FdoSmPhRdConstraintReader(),
    mConstraintName(constraintType.Upper()),
	mTableName(tableName),
    mOwner(owner)
{
    SetSubReader(
        MakeReader(owner,DbObjectName2Objects(tableName),(FdoSmPhRdTableJoin*) NULL,constraintType)
    );
}
예제 #18
0
FdoSmPhRdMySqlConstraintReader::FdoSmPhRdMySqlConstraintReader(
    FdoSmPhOwnerP owner,
    FdoSmPhRdTableJoinP join,
    FdoStringP constraintType
) :
    FdoSmPhRdConstraintReader(),
    mConstraintName(constraintType.Upper()),
    mOwner(owner)
{
    FdoStringsP tableNames = FdoStringCollection::Create();

    SetSubReader(
        MakeReader(owner,tableNames,join,constraintType)
    );
}
예제 #19
0
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;
}
예제 #20
0
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
    );
}
예제 #21
0
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 );
}
예제 #22
0
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 SuperMapLpPropertyDefinition::ConvertPhysicalToLogical(UGC::UGFieldInfo* fieldInfo)
{
	if(m_fieldInfo == NULL)
	{
		m_fieldInfo = fieldInfo;
	}
    VALIDATE_POINTER(m_fieldInfo);

	// 逻辑的FDO属性名及为物理数据集的字段名
	//FdoStringP pLogicalPropertyName = fieldInfo->m_strName;
	FdoStringP pLogicalPropertyName = SuperMapUtil::StringToWString(fieldInfo->m_strName.Cstr()).c_str(); //modified by majun, 支持汉字字段
	FdoString* logicalPropertyName = (FdoString*)pLogicalPropertyName;

	FdoString* logicalPropertyDescription = L"";
	
	// 创建逻辑属性
	m_logicalProperty = FdoDataPropertyDefinition::Create(logicalPropertyName, logicalPropertyDescription);

	// 属性字段物理属性转换
	FdoDataType data_type ;
	FdoInt32 nType = fieldInfo->m_nType; // ugc的字段类型
	//TRACE(_T("SuperMapLpPropertyDefinition::ConvertPhysicalToLogical..[%ls]...[%d]\n"), logicalPropertyName, nType);
	switch(nType)
	{
	case UGC::UGFieldInfo::Boolean:
		data_type = FdoDataType_Boolean;
		break;
	case UGC::UGFieldInfo::Byte:
	case UGC::UGFieldInfo::Char:
		data_type = FdoDataType_Byte;
		break;
	case UGC::UGFieldInfo::Integer:
		data_type = FdoDataType_Int16;
		break;
	case UGC::UGFieldInfo::Long:   
		data_type = FdoDataType_Int32;
		break;
	case UGC::UGFieldInfo::Single:
	case UGC::UGFieldInfo::Float:
		data_type = FdoDataType_Single;
		break;
	case UGC::UGFieldInfo::Double:
		data_type = FdoDataType_Double;
		break;
	case UGC::UGFieldInfo::Date:
	case UGC::UGFieldInfo::Time:
		data_type = FdoDataType_DateTime;
		break;
	case UGC::UGFieldInfo::Decimal:
		data_type = FdoDataType_Decimal;
		break;
	case UGC::UGFieldInfo::Binary:
	case UGC::UGFieldInfo::LongBinary:
	case UGC::UGFieldInfo::VarBinary:
	case UGC::UGFieldInfo::TimeStamp:
		data_type = FdoDataType_BLOB;
		break;
	case UGC::UGFieldInfo::Text:
	case UGC::UGFieldInfo::Memo:
	case UGC::UGFieldInfo::NVarChar:
		//data_type = FdoDataType_CLOB;
		data_type = FdoDataType_String; 
		break;
	default:
		return;  //其他可能类型字段暂不转换
	}


	m_logicalProperty->SetDataType(data_type);

	// 如果是字符串类型设置长度
	if (data_type == FdoDataType_String)
	{
		if(fieldInfo->m_nType == UGC::UGFieldInfo::NVarChar)
			m_logicalProperty->SetLength(fieldInfo->m_nSize * 2);
		else
			m_logicalProperty->SetLength(fieldInfo->m_nSize);
	}
		
	// 如果是十进制类型设置位数和精度
	if (data_type == FdoDataType_Decimal)
	{
		m_logicalProperty->SetPrecision(fieldInfo->m_nPrecision);
		m_logicalProperty->SetScale(fieldInfo->m_nScale);
	}

	FdoPtr<FdoClassDefinition> logicalClass = m_parentLpClass->GetLogicalClass(); //各种逻辑属性要加入此类中
		
	FdoPtr<FdoPropertyDefinitionCollection> logicalProperties = logicalClass->GetProperties();

	// 如果有重复字段名返回
	if (logicalProperties->Contains (m_logicalProperty->GetName ())) 
		return;

	// modified by zhouxu 2007-12-18
	// 对Sm开头的字段除了SmUserId以外都设为只读。/ 并且加为逻辑类的标识属性
	if((0 == wcscmp (L"SmGeometry", pLogicalPropertyName)) 
	|| (0 == wcscmp(L"SMGEOMETRY",pLogicalPropertyName))) //modified by zhouxu 2007-12-7 //added by majun ,要素类中去掉SmGeometry字段
	{
		return;
	}
	else if((0 == wcscmp(L"SmUserID", pLogicalPropertyName))
	|| (0 == wcscmp(L"SMUSERID", pLogicalPropertyName)))
	{
		m_logicalProperty->SetReadOnly(false);
		m_logicalProperty->SetIsAutoGenerated(false);	
		m_logicalProperty->SetNullable(false);
		logicalProperties->Add(m_logicalProperty);
	}
	else if((0 == wcscmp(L"Sm", pLogicalPropertyName.Mid(0,2)))
		|| (0 == wcscmp(L"SM", pLogicalPropertyName.Mid(0,2))))
	{
		m_logicalProperty->SetReadOnly(true);//m_logicalProperty->SetReadOnly(true);
		m_logicalProperty->SetIsAutoGenerated(true);
		m_logicalProperty->SetNullable(false);
		//// 作为一个标识属性
		//FdoPtr<FdoDataPropertyDefinitionCollection> pIdentityProperties = logicalClass->GetIdentityProperties();
		//VALIDATE_POINTER(pIdentityProperties);
		logicalProperties->Add(m_logicalProperty);
		//pIdentityProperties->Add(m_logicalProperty);
	}
	else
	{
		m_logicalProperty->SetReadOnly(false);
		m_logicalProperty->SetIsAutoGenerated(false);	
		m_logicalProperty->SetNullable(true);
		logicalProperties->Add(m_logicalProperty);
	}

}
void FdoSpatialContextTest::DoTest( bool hasMetaSchema )
{
    FdoPtr<FdoIConnection> connection;
    StaticConnection* staticConn = NULL;

    try {
        if ( !hasMetaSchema ) {
            staticConn = UnitTestUtil::NewStaticConnection();
            staticConn->connect();
            UnitTestUtil::CreateDBNoMeta( 
                staticConn->CreateSchemaManager(),
                UnitTestUtil::GetEnviron("datastore", DB_NAME_SUFFIX)
            );
        }


        // delete, re-create and open the datastore
		printf( "Initializing Connection ... \n" );
		connection = UnitTestUtil::CreateConnection(
			hasMetaSchema,
			hasMetaSchema,
            DB_NAME_SUFFIX,
            0,
            NULL,
            0
		);

		printf( "Creating Spatial Contexts ... \n" );

        UnitTestUtil::CreateSpatialContext( connection, L"Bermuda", L"Bermuda 1957", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Rectangular", L"", 0, 0, 1000, 1000 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Bermuda Duplicate", L"Bermuda 1957", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Luxembourg Delete", L"Luxembourg 1930", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"South", L"Australian Antarctic", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"sc_2", L"Puerto Rico", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"South Delete", L"Australian Antarctic", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"sc_1", L"NAD27", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"South Duplicate", L"Australian Antarctic", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Liberia by WKT", L"", 0, 0, 10, 10, L"GEOGCS[\"Liberia 1964\", DATUM[\"Liberia 1964\", ELLIPSOID[\"Clarke 1880 (RGS)\", 6378249.145, 293.465]], PRIMEM[\"Greenwich\", 0], UNIT[\"Degree\", 0.0174532925199433]]" ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Qatar wrong name", L"Bermuda 1957", 0, 0, 10, 10, L"GEOGCS[\"Qatar 1974\", DATUM[\"Qatar 1974\", ELLIPSOID[\"International 1924\", 6378388, 297]], PRIMEM[\"Greenwich\", 0], UNIT[\"Degree\", 0.0174532925199433]]" ); 
        UnitTestUtil::CreateSpatialContext( connection, L"California", L"CA-I", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Bermuda Mentor", L"Bermuda.LL", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Mentor by WKT", L"", 0, 0, 10, 10, L"PROJCS[\"Quebec test\",GEOGCS[\"For testing only\",DATUM[\"Test\",SPHEROID[\"NAD 27\",6300000,123.465,]]]]" ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Rectangular (Metre)", L"XY-M", 0, 0, 10, 10); 
        UnitTestUtil::CreateSpatialContext( connection, L"Rectangular (Feet)", L"XY-FT", 0, 0, 10, 10); 

        connection->Close();
        connection->Open();

		printf( "Deleting Spatial Contexts ... \n" );

        UnitTestUtil::DeleteSpatialContext( connection, L"Luxembourg Delete" );
        UnitTestUtil::DeleteSpatialContext( connection, L"South Delete" );

        connection->Close();
        connection->Open();

        CreateSchema( connection, hasMetaSchema );

		printf( "Writing output ... \n" );

        FdoStringP datastore = UnitTestUtil::GetEnviron("datastore", DB_NAME_SUFFIX);

        FdoIoMemoryStreamP stream1 = FdoIoMemoryStream::Create();

        FdoXmlSpatialContextFlagsP flags = FdoXmlSpatialContextFlags::Create(
            L"fdo.osgeo.org/schemas/feature",
            FdoXmlFlags::ErrorLevel_Normal,
            true,
            FdoXmlSpatialContextFlags::ConflictOption_Add,
            true
        );

        UnitTestUtil::ExportDb( 
            connection, 
            stream1, 
            flags,
            false, 
            FdoStringP(L"Fdo") + datastore
        );

   		UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(1, hasMetaSchema, false) ) );

        UnitTestUtil::CheckOutput( 
            GenFileName( 1, hasMetaSchema, true ),
            UnitTestUtil::GetOutputFileName( GenFileName(1, hasMetaSchema, false) )
        );

        InsertFeatures( connection );

        stream1 = FdoIoMemoryStream::Create();

        UnitTestUtil::ExportDb( 
            connection, 
            stream1, 
            flags,
            false, 
            FdoStringP(L"Fdo") + datastore,
            L"AutoGen",
            true
        );

   		UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(2, hasMetaSchema, false) ) );

        UnitTestUtil::CheckOutput( 
            GenFileName( 2, hasMetaSchema, true ),
            UnitTestUtil::GetOutputFileName( GenFileName(2, hasMetaSchema, false) )
        );

        if ( !hasMetaSchema ) {
            CreateTables( staticConn, datastore );

            connection->Close();
            connection->Open();

            stream1 = FdoIoMemoryStream::Create();

            UnitTestUtil::ExportDb( 
                connection, 
                stream1, 
                flags,
                false, 
                FdoStringP(L"Fdo") + datastore,
                L"AutoGen",
                true
            );

   		    UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) ) );

            UnitTestUtil::CheckOutput( 
                GenFileName( 3, hasMetaSchema, true ),
                UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) )
            );


            try {
                UnitTestUtil::CreateSpatialContext( connection, L"Nowhere", L"JunkCS", 0, 0, 10, 10 ); 
                CPPUNIT_FAIL( "Setting unsupported coordinate system by name supposed to fail" );
            }
            catch (FdoException* e ) {
#ifdef _WIN32
#ifdef _DEBUG
                FdoStringP expectedMessage = L" Error creating spatial context Nowhere, coordinate system JunkCS is not in current datastore. ";
                FdoString* pMessage = wcschr( e->GetExceptionMessage(), ')' );
                if (pMessage) pMessage++;
#else
                FdoStringP expectedMessage = L"Error creating spatial context Nowhere, coordinate system JunkCS is not in current datastore. ";
                FdoString* pMessage = e->GetExceptionMessage();
#endif
                CPPUNIT_ASSERT( pMessage && expectedMessage.ICompare(pMessage) == 0 );
#endif
                FDO_SAFE_RELEASE(e);
            }

            try {
                UnitTestUtil::CreateSpatialContext( connection, L"California2", L"", 0, 0, 10, 10, L"PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]" ); 
                CPPUNIT_FAIL( "Setting unsupported coordinate system by wkt supposed to fail" );
            }
            catch (FdoException* e ) {
#ifdef _WIN32
#ifdef _DEBUG
                FdoStringP expectedMessage = L" Error creating spatial context California2, coordinate system catalog does not contain entry for WKT 'PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]' ";
                FdoString* pMessage = wcschr( e->GetExceptionMessage(), ')' );
                if (pMessage) pMessage++;
#else
                FdoStringP expectedMessage = L"Error creating spatial context California2, coordinate system catalog does not contain entry for WKT 'PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]' ";
                FdoString* pMessage = e->GetExceptionMessage();
#endif
                CPPUNIT_ASSERT( pMessage && expectedMessage.ICompare(pMessage) == 0 );
#endif
                FDO_SAFE_RELEASE(e);
            }
        }
        else {
            UnitTestUtil::CreateSpatialContext( connection, L"Nowhere", L"JunkCS", 0, 0, 10, 10 ); 
            UnitTestUtil::CreateSpatialContext( connection, L"California2", L"CA_I", 0, 0, 10, 10, L"PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]" ); 

            stream1 = FdoIoMemoryStream::Create();
            UnitTestUtil::ExportDb( 
                connection, 
                stream1, 
                flags,
                false, 
                FdoStringP(L"Fdo") + datastore,
                L"AutoGen",
                true
            );

            UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) ) );

            UnitTestUtil::CheckOutput( 
                GenFileName( 3, hasMetaSchema, true ),
                UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) )
            );

        }

        delete staticConn;
        connection->Close();
    }
    catch ( ... )
    {
        try {
            if ( staticConn ) delete staticConn;
            if ( connection ) connection->Close();
        }
        catch ( ... ) {
        }

        throw;
    }
}
예제 #25
0
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(...){}
}
예제 #26
0
wchar_t *OdbcConnectionUtil::GetConnectionString(StringConnTypeRequest pTypeReq, FdoString *suffix, bool bAddExtraneousSpaces)
{
    FdoStringP service = UnitTestUtil::GetEnviron("service");
    FdoStringP username = UnitTestUtil::GetEnviron("username");
    FdoStringP password = UnitTestUtil::GetEnviron("password");
    FdoStringP datastore = UnitTestUtil::GetEnviron("datastore", suffix);
    FdoStringP dsnname = UnitTestUtil::GetEnviron("dsnname");
	
	FdoStringP OracleDriverName = theOracleDriverName;

	static wchar_t connectString[200];
	connectString[0] = L'\0';

	switch (pTypeReq)
	{
		case Connection_WithDatastore:
			if (m_ProviderActive == L"OdbcMySql")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"ConnectionString=\"DRIVER=%ls;SERVER=%ls;DATABASE=%ls;USER=%ls;PASSWORD=%ls;OPTION=3;\"", 
                    (FdoString*) MYSQL_ODBC_DRIVER_NAME,
                    (FdoString*) service, 
                    (FdoString*) datastore, 
                    (FdoString*) username, 
                    (FdoString*) password
                );
			else if (m_ProviderActive == L"OdbcSqlServer")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"ConnectionString=\"DRIVER={SQL Server};SERVER=%ls;DATABASE=%ls;UID=%ls;PWD=%ls;\"", 
                    (FdoString*) service, 
                    (FdoString*) datastore, 
                    (FdoString*) username, 
                    (FdoString*) password
                );
			else if (m_ProviderActive == L"OdbcSybase")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"ConnectionString=\"DRIVER={Adaptive Server Enterprise};SERVER=%ls;PORT=5000;DATABASE=%ls;UID=%ls;PWD=%ls;\"", 
                    (FdoString*) service, 
                    (FdoString*) datastore, 
                    (FdoString*) username, 
                    (FdoString*) password
                );
			else if (m_ProviderActive == L"OdbcOracle")
			{
				FdoStringP pDatastore = datastore;
				pDatastore = pDatastore.Upper();
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"ConnectionString=\"DRIVER={%ls};UID=%ls;PWD=%ls;DBQ=%ls;XSM=%ls;\"", 
                    (FdoString*)OracleDriverName, 
                    (FdoString*)pDatastore, 
                    (FdoString*)password, 
                    (FdoString*)service, 
                    (FdoString*)pDatastore);
			}
			else if (m_ProviderActive == L"OdbcAccess")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*)dsnname
                );
			else if (m_ProviderActive == L"OdbcExcel")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*) dsnname
                );
			else if (m_ProviderActive == L"OdbcText")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*) dsnname
                );
		break;

		case Connection_NoDatastore:
			if (m_ProviderActive == L"OdbcMySql")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"ConnectionString=\"DRIVER=%ls;SERVER=%ls;USER=%ls;PASSWORD=%ls;OPTION=3;\"", 
                    (FdoString*)MYSQL_ODBC_DRIVER_NAME,
                    (FdoString*)service, 
                    (FdoString*)username, 
                    (FdoString*)password
                );
			else if (m_ProviderActive == L"OdbcSqlServer")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"ConnectionString=\"DRIVER={SQL Server};SERVER=%ls;UID=%ls;PWD=%ls;\"", 
                    (FdoString*)service, 
                    (FdoString*)username, 
                    (FdoString*)password
                );
			else if (m_ProviderActive == L"OdbcSybase")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"ConnectionString=\"DRIVER={Adaptive Server Enterprise};SERVER=%ls;PORT=5000;UID=%ls;PWD=%ls;\"", 
                    (FdoString*)service, 
                    (FdoString*)username, 
                    (FdoString*)password
                );
			else if (m_ProviderActive == L"OdbcOracle")
			{
				FdoStringP pDatastore = datastore;
				pDatastore = pDatastore.Upper();
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"ConnectionString=\"DRIVER={%ls};UID=%ls;PWD=%ls;DBQ=%ls;\"", 
                    (FdoString*)OracleDriverName, 
                    (FdoString*)pDatastore /*username*/, 
                    (FdoString*)password, 
                    (FdoString*)service
                );
			}
			else if (m_ProviderActive == L"OdbcAccess")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*)dsnname
                );
			else if (m_ProviderActive == L"OdbcExcel")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*)dsnname
                );
			else if (m_ProviderActive == L"OdbcText")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*)dsnname
                );
		break;
		
		case Connection_WithDSN:
			if (m_ProviderActive == L"OdbcMySql")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=%ls;Password=%ls;", 
                    (FdoString*)dsnname, 
                    (FdoString*)username, 
                    (FdoString*)password
                );
			else if (m_ProviderActive == L"OdbcSqlServer")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=%ls;Password=%ls;", 
                    (FdoString*)dsnname, 
                    (FdoString*)username, 
                    (FdoString*)password
                );
			else if (m_ProviderActive == L"OdbcOracle")
			{
			FdoStringP pDatastore = datastore;
			pDatastore = pDatastore.Upper();
            swprintf( 
                connectString, 
                sizeof(connectString)/sizeof(wchar_t), 
                L"DataSourceName=%ls;UserId=%ls;Password=%ls;", 
                (FdoString*)dsnname, 
                (FdoString*)pDatastore, 
                (FdoString*)password
            );
			}
			else if (m_ProviderActive == L"OdbcSybase")
			{
                swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=%ls;Password=%ls;", 
                    (FdoString*)dsnname, 
                    (FdoString*)username, 
                    (FdoString*)password
                );
			}
			else if (m_ProviderActive == L"OdbcAccess")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*)dsnname
                );
			else if (m_ProviderActive == L"OdbcDbase")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*)dsnname
                );
			else if (m_ProviderActive == L"OdbcExcel")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*)dsnname
                );
			else if (m_ProviderActive == L"OdbcText")
				swprintf( 
                    connectString, 
                    sizeof(connectString)/sizeof(wchar_t), 
                    L"DataSourceName=%ls;UserId=;Password=;", 
                    (FdoString*)dsnname
                );
		break;
		case Connection_OraSetup:
			swprintf( 
                connectString, 
                sizeof(connectString)/sizeof(wchar_t), 
                L"ConnectionString=\"DRIVER={%ls};UID=%ls;PWD=%ls;DBQ=%ls;;\"", 
                (FdoString*)OracleDriverName, 
                (FdoString*)username, 
                (FdoString*)password, 
                (FdoString*)service
            );
		break;
	}
	return connectString;
}
예제 #27
0
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;
}