setCurrentDatabase()

The sqlLib.setCurrentDatabase() system function makes the specified database currently active. Each run unit has a current connection (see "Run unit"). The SQL statements operate on the current connection. Each new sqlLib.connect() call typically changes the current connection. To reset your connection to a previous value, use sqlLib.setCurrentDatabase().

Syntax

  sqlLib.setCurrentDatabase(database STRING in)
database
A database name or alias that was specified in sqlLib.connect(). Input can be any variable or expression that is assignment compatible with the STRING type (see "Assignment compatibility in EGL").

Example

The following example shows how to use sqlLib.setCurrentDatabase():

connect( "db1a", "user", "pwd" );
// Drop table xyz from database db1a
execute #sql{ drop table xyz };

connect( "db1b", "user", "pwd" );
// Drop table xyz from database db1b
execute #sql{ drop table xyz };

setCurrentDatabase( "db1a" );
// Drop table xyz2 from database db1a
execute #sql{ drop table xyz2 };

// Disconnect from db1a (the current connection)
disconnect( "db1a" );

// Since the current connection was closed by
// the previous statement, EGL connects to
// the default database before running this statement
execute #sql{ drop table xyz3 };
				
// Disconnect from the current connection,
// whatever it happens to be
disconnect();

setCurrentDatabase( "db1b" );
// Drop table xyz2 from database db1b
execute #sql{ drop table xyz2 };

Feedback