Пример #1
0
void Clone_Current_Record_Light( 
	vuint16				inFieldCount,
	I_Table_Ptr 		inpSourceTable, 
	I_Table_Ptr			inpTargetTable )
{
	// For each field in target:
	//

	for( vuint16 j = 1; j <= inFieldCount; ++j )
	{
		I_Field_Ptr pTargetFld = inpTargetTable->get_Field( j );
		FBL_CHECK( pTargetFld );
		FBL_CHECK( pTargetFld->get_IsMethod() == false );

		// Skip identity:
		if( pTargetFld->get_Identity() )
			continue;

		I_Field_Ptr pSourceFld = inpSourceTable->get_Field( j );
		FBL_CHECK( pSourceFld );

		//
		// Clone DATA:
		//
		VALUE_TYPE fldType = pTargetFld->get_Type();
		Clone_Current_Value( fldType, pSourceFld, pTargetFld );
	}
}
Пример #2
0
I_Field_Ptr CreateEnumField( 
	I_Table_Ptr 			inTable, 
	const String& 			inName,
	I_Type_Enumerated_Ptr 	inpType,
	vuint16					inFlags )
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	

	props->Add( new Prop_EnumType(inpType) );

	// ---------------
	I_Field_Ptr pField;

	switch( inpType->get_MaxIdentCount() )
	{
		case ENUM_8_IDENT_COUNT:
		{
			pField = inTable->CreateField( inName, kTypeEnum8, inFlags, props );
		} break;

		case ENUM_16_IDENT_COUNT:
		{
			pField = inTable->CreateField( inName, kTypeEnum16, inFlags, props );
		} break;

		default:
		{
			FBL_Throw( xFeatureError( ERR_FEATURE_NOT_SUPPORTED, "Not enum8 or enum16" ) );
		}
	}
	

	return pField;
}
Пример #3
0
I_Field_Ptr CreateVariantField(
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	vuint16			inFlags )
{
	I_Field_Ptr pField = inTable->CreateField( inName, kTypeVariant, inFlags );
	return pField;
}
Пример #4
0
ArrayOfValues_Ptr GetNotBLOBValues( I_Table_Ptr inTable )
{
	FBL_CHECK( inTable );
	ArrayOfValues_Ptr result;

	vuint16 fldCount = inTable->get_FieldCount();
	if( fldCount )
		result = new ArrayOfValues();

	for( vuint16 i = 1; i <= fldCount; ++i )
	{
		I_Field_Ptr	pField = inTable->get_Field( i );
		I_Value_Ptr pValue;

		switch( pField->get_Type() )
		{
			case kTypeBLOB:
			case kTypePicture: 
			{
				;
			} break;

			default: 
			{
				// IS: 25.02.2008
				// http://valentina-db.com/bt/view.php?id=3048
				//pValue = pField->get_Value(forAdd);
				pValue = fbl_const_cast( pField->get_Value() );
				FBL_CHECK(pValue);							

			} break;
		}
		
		result->AddItem( pValue );
	}

	return result;
}
Пример #5
0
I_Field_Ptr CreateMoneyField(
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	vuint16			inFlags,
	const String& 	inMethod )
{
	I_PropertyContainer_Ptr props = new PropertyContainer();

	if( inMethod.isEmpty() == false )
		props->Add( new Prop_MethodSql( inMethod ) );

	I_Field_Ptr pField = inTable->CreateField( inName, kTypeMoney, inFlags, props );

	return pField;
}
Пример #6
0
I_Field_Ptr CreatePictureField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	vuint32			inSegmentSize,
	vuint16			inFlags )	
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	
	
	props->Add( new Prop_SegmentSize(inSegmentSize) );

	// ---------------
	I_Field_Ptr pField = inTable->CreateField( inName, kTypePicture, inFlags, props );
		
	return pField;
}
Пример #7
0
I_Field_Ptr CreateStringField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	vuint32			inMaxLength,
	vuint16			inFlags,
	const String& 	inMethod )	
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	

	props->Add( new Prop_MaxLen(inMaxLength) );

	if( inMethod.isEmpty() == false )
		props->Add( new Prop_MethodSql( inMethod ) );

	// ---------------
	I_Field_Ptr pField = inTable->CreateField( inName, kTypeString, inFlags, props );
		
	return pField;
}
Пример #8
0
I_Field_Ptr CreateTextField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	vuint32			inSegmentSize,
	vuint16			inFlags,
	const String& 	inMethod )	
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	
	
	props->Add( new Prop_SegmentSize(inSegmentSize) );

	if( inMethod.isEmpty() == false )
		props->Add( new Prop_MethodSql( inMethod ) );

	// ---------------
	I_Field_Ptr pField = inTable->CreateField( inName, kTypeText, inFlags, props );
		
	return pField;
}
Пример #9
0
I_Field_Ptr CreateObjectPtr( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	I_Table_Ptr 	inTarget,
	EOnDeletion		inOnDeletion,
	vuint16			inFlags,
	const String& 	inLinkName )
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	
	
	props->Add( new Prop_Target(inTarget) );
	props->Add( new Prop_OnDeletion(inOnDeletion) ); 
	
	if( inLinkName.isEmpty() == false )
		props->Add( new Prop_LinkName( inLinkName ) );

	// ---------------
	I_Field_Ptr pField = inTable->CreateField( inName, kTypeObjectPtr, inFlags, props );
		
	return pField;
}
Пример #10
0
I_Field_Ptr CreateDoubleField(
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	vuint16			inFlags,
	const String& 	inMethod,
	vuint16			inPrecision,
	vuint16			inScale )
{
	I_PropertyContainer_Ptr props = new PropertyContainer();

	if( inPrecision )
		props->Add( new Prop_Precision( inPrecision ) );
	if( inScale )
		props->Add( new Prop_Scale( inScale ) );

	if( inMethod.isEmpty() == false )
		props->Add( new Prop_MethodSql( inMethod ) );

	I_Field_Ptr pField = inTable->CreateField( inName, kTypeDouble, inFlags, props );

	return pField;
}
Пример #11
0
FBL_Begin_Namespace


/**********************************************************************************************/
I_Field_Ptr CreateNumericField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	VALUE_TYPE		inType,
	vuint16			inFlags,
	const String& 	inMethod )
{
	I_PropertyContainer_Ptr props;	
	
	//if( inMethod != NULL && *inMethod != 0 )
	if( inMethod.isEmpty() == false )
	{
		props = new PropertyContainer();
		props->Add( new Prop_MethodSql( inMethod ) );
	}
	
	I_Field_Ptr pField = inTable->CreateField( inName, inType, inFlags, props );

	return pField;
}
Пример #12
0
FBL_End_Namespace


/**********************************************************************************************/
VSQL_Begin_Namespace


/**********************************************************************************************/
I_Table_Ptr CopyCursorToNewTable( 
	VSQL::I_Cursor_Ptr		inpSourceCursor,
	VSQL::I_SqlDatabase_Ptr	inpTargetDatabase,
	const String&			inNewTableName,
	EStorageType			inNewTableStorage,
	bool					inCopyRecords )
{
	if( inpSourceCursor == nullptr || inpTargetDatabase == nullptr )
		return nullptr;

	I_Database_Ptr pTargetDb = inpTargetDatabase->get_BaseDatabase();
	I_Table_Ptr pSourceTable = inpSourceCursor->get_Table();

	// Create table	
	I_Table_Ptr pTargetTable = pTargetDb->CreateTable( inNewTableName, kTblPermanent, inNewTableStorage );

	// create fields
	try
	{
		CloneFieldsLight( pSourceTable, pTargetTable );
	}
	catch(...)
	{
		// it could be "SELECT f1, f1 FROM t1" - in
		// this case we are throwing exceptions.
		//
		pTargetDb->DropTable( pTargetTable );
		throw;
	}

	if( inCopyRecords )
	{
		// Create records
		vuint32 recCount = pSourceTable->get_RecordCount();
		vuint16 fldCount = pTargetTable->get_FieldCount();


		// During reading the data we can meet corrupted fields,
		// we want ignore this corruptions and logging it.
		// So we ask table continue read even if it meet corruption in some field.
		pSourceTable->put_ForceRead( true );

		// for each record:
		pSourceTable->FirstRecord();			
		for( vuint32 k = 1; k <= recCount; ++k )
		{					
			pTargetTable->SetBlank();		
			Clone_Current_Record_Light( fldCount, pSourceTable, pTargetTable );			
			pTargetTable->AddRecord();		
			pSourceTable->NextRecord();		
		}				

		pSourceTable->put_ForceRead( false );
	}

	return pTargetTable;
}
Пример #13
0
void CloneFieldsLight( 
	I_Table_Ptr 		inpTableSource, 
	I_Table_Ptr 		inpTableTarget )
{
	// Light because of 
	// 1. inpTableSource assumed to be a cursor (no ObjectPtrs, RecID, OID).
	// 2. inpTableTarget will be just a "data-snapshot" of inpTableSource
	//    (most of the flags and some properties like method-text are ignored)
	// 

	vuint16 fldCount = inpTableSource->get_FieldCount();
	for( vuint16 i = 1; i <= fldCount; ++i )
	{
		I_Field_Ptr pSourceFld = inpTableSource->get_Field(i);

		// Flags
		vuint16 fldFlags = fNone;
		if( pSourceFld->get_Nullable() )
			fldFlags |= fNullable;

		// At least for now we will ignore any flag except nullable
		// because of who need to get indexed (especially indexBywords -
		// btw here is a problem - asking for that we create some default tmp
		// index) result.
		// But note that there are some fields for which some flags are always ON!
		// ( indexed for boolean for example)
/*
		if( pSourceFld->get_Indexed() )
			fldFlags |= fIndexed;
		if( pSourceFld->get_Unique() )
			fldFlags |= fIndexUnique;
		if( pSourceFld->get_IndexStyle() )
			fldFlags |= fIndexByWords;
		
*/
		// No sense to keep identity, because cursor's field keeps some particular values
		// and we have to store exactly that values
		//
		//if( pSourceFld->get_Identity() )
		//	fldFlags |= fIdentity;
		
		// Remove any method property. Because it could be the methods
		// which are based on fields which are not available in target table.
		// "SELECT f1+1 FROM t2"
		// So every field will be snapshot of original one.
		//
		//if( pSourceFld->get_IsMethod() )
		//	fldFlags |= fMethod;

		vuint32 fldType = pSourceFld->get_Type();
		// Could not be objectPtr, RecID, OID in the target table because it is impossible 
		// to have those field types in the cursor.
		FBL_CHECK( fldType != kTypeObjectPtr && fldType != kTypeRecID && fldType != kTypeOID );

		// Type and properties
		I_PropertyContainer_Ptr properties;
		// Properties
		properties = pSourceFld->get_Properties();
		if( pSourceFld->get_IsMethod() )
		{
			properties->Remove( "METHOD_TEXT" );
			properties->Remove( "METHOD_TREE" );
		}

		// In case of client-cursor field in vclient environment (no properties at all)
		// register max length property manually.
		if( properties == nullptr )
		{
			properties = new PropertyContainer();	
			properties->Add( new Prop_MaxLen( pSourceFld->get_MaxLength() ) );
		}
		

		// Create target field
		I_Field_Ptr pTargetFld = inpTableTarget->CreateField( 
			pSourceFld->get_Name(), 
			fldType, 
			fldFlags,														
			properties );
	}	
}