sqldata/sqlociapi.cpp
// Remove foreign key constraints on the specified child table
Remove foreign key constraints on the specified child table
Remove foreign key constraints on the specified child table
int SqlOciApi::DropReferencesChild(const char* table, size_t *time_spent, int *keys)
{
	if(table == NULL)
		return -1;
	size_t start = (time_spent != NULL) ? Os::GetTickCount() : 0;
	int found = 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 != 'R')
			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;
		std::string drop = "ALTER TABLE ";
		drop += table;
		drop += " DROP CONSTRAINT ";
		drop += c;
		rc = ExecuteNonQuery(drop.c_str(), NULL);
		found++;
	}
	if(keys != NULL)
		*keys = found;
	if(time_spent != NULL)
		*time_spent = GetTickCount() - start;
	return rc;
}
int SqlOciApi :: DropReferencesChild ( const char * table , size_t * time_spent , int * keys ) { if ( table == NULL ) return -1 ; size_t start = ( time_spent != NULL ) ? Os :: GetTickCount ( ) : 0 ; int found = 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 != ' ' ) 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 ; std :: string drop = " " ; drop += table ; drop += " " ; drop += c ; rc = ExecuteNonQuery ( drop . c_str ( ) , NULL ) ; found ++ ; } if ( keys != NULL ) * keys = found ; if ( time_spent != NULL ) * time_spent = GetTickCount ( ) - start ; return rc ; }
Remove foreign key constraints on the specified child table
Remove foreign key constraints on the specified child table
// Find a foreing key constraint defined on this table // Not this table (compare case-insensitive as objects in DDL can be in any case) // Generate ALTER TABLE child DROP CONSTRAINT name