sqldata/sqlociapi.cpp
// Remove foreign key constraints referencing to the parent table
// Foreign keys are removed before transfer as CASCADE CONSTRAINTS causes 'resource busy' errors in concurrent environment
Remove foreign key constraints referencing to the parent table
Foreign keys are removed before transfer as CASCADE CONSTRAINTS causes 'resource busy' errors in concurrent environment
Remove foreign key constraints referencing to the parent table Foreign keys are removed before transfer as CASCADE CONSTRAINTS causes ' resource busy ' errors in concurrent environment
int SqlOciApi::DropReferences(const char* table, size_t *time_spent)
{
	if(table == NULL)
		return -1;
	size_t start = (time_spent != NULL) ? Os::GetTickCount() : 0;
	std::string schema;
	std::string object;
	SplitQualifiedName(table, schema, object);
	int rc = 0;
	for(std::list<SqlConstraints>::iterator i = _table_constraints.begin(); i != _table_constraints.end(); i++)
	{
		if((*i).type != 'P' && (*i).type != 'U')
			continue;
		char *s = (*i).schema;
		char *t = (*i).table;
		char *c = (*i).constraint;
		if(s == NULL || t == NULL || c == NULL)
			continue;
		if(_stricmp(t, object.c_str()) != 0 || _stricmp(s, schema.c_str()) != 0)
			continue;
		for(std::list<SqlConstraints>::iterator k = _table_constraints.begin(); k != _table_constraints.end(); k++)
		{
			if((*k).type != 'R')
				continue;
			char *fk_s = (*k).schema;
			char *fk_t = (*k).table;
			char *fk_c = (*k).constraint;
			char *pk_s = (*k).r_schema;
			char *pk_c = (*k).r_constraint;
			if(fk_s == NULL || fk_t == NULL || fk_c == NULL || pk_s == NULL || pk_c == NULL)
				continue;
			if(strcmp(c, pk_c) != 0 && strcmp(s, pk_s) != 0)
				continue;
			std::string drop = "ALTER TABLE ";
			drop += fk_s;
			drop += ".";
			drop += fk_t;
			drop += " DROP CONSTRAINT ";
			drop += fk_c;
			rc = ExecuteNonQuery(drop.c_str(), NULL);
		}		
	}
	if(time_spent != NULL)
		*time_spent = GetTickCount() - start;
	return rc;
}
int SqlOciApi :: DropReferences ( const char * table , size_t * time_spent ) { if ( table == NULL ) return -1 ; size_t start = ( time_spent != NULL ) ? Os :: GetTickCount ( ) : 0 ; std :: string schema ; std :: string object ; SplitQualifiedName ( table , schema , object ) ; int rc = 0 ; for ( std :: list < SqlConstraints > :: iterator i = _table_constraints . begin ( ) ; i != _table_constraints . end ( ) ; i ++ ) { if ( ( * i ) . type != ' ' && ( * i ) . type != ' ' ) continue ; char * s = ( * i ) . schema ; char * t = ( * i ) . table ; char * c = ( * i ) . constraint ; if ( s == NULL || t == NULL || c == NULL ) continue ; if ( _stricmp ( t , object . c_str ( ) ) != 0 || _stricmp ( s , schema . c_str ( ) ) != 0 ) continue ; for ( std :: list < SqlConstraints > :: iterator k = _table_constraints . begin ( ) ; k != _table_constraints . end ( ) ; k ++ ) { if ( ( * k ) . type != ' ' ) continue ; char * fk_s = ( * k ) . schema ; char * fk_t = ( * k ) . table ; char * fk_c = ( * k ) . constraint ; char * pk_s = ( * k ) . r_schema ; char * pk_c = ( * k ) . r_constraint ; if ( fk_s == NULL || fk_t == NULL || fk_c == NULL || pk_s == NULL || pk_c == NULL ) continue ; if ( strcmp ( c , pk_c ) != 0 && strcmp ( s , pk_s ) != 0 ) continue ; std :: string drop = " " ; drop += fk_s ; drop += " " ; drop += fk_t ; drop += " " ; drop += fk_c ; rc = ExecuteNonQuery ( drop . c_str ( ) , NULL ) ; } } if ( time_spent != NULL ) * time_spent = GetTickCount ( ) - start ; return rc ; }
Remove foreign key constraints referencing to the parent table
Foreign keys are removed before transfer as CASCADE CONSTRAINTS causes 'resource busy' errors in concurrent environment
Remove foreign key constraints referencing to the parent table Foreign keys are removed before transfer as CASCADE CONSTRAINTS causes ' resource busy ' errors in concurrent environment
// Find a primary or unique constraint defined on this table // Not this table (compare case-insensitive as objects in DDL can be in any case) // Now find a foreign key referencing to this primary or unqiue constraint // Not this constraint // Generate ALTER TABLE child DROP CONSTRAINT name