defineDatabaseAlias()
sqlLib.defineDatabaseAlias() 시스템 변수는 사용자의 코드가 이미 연결된
데이터베이스에 대한 새 연결을 설정하는 데 사용할 수 있는 별명을 작성합니다. 별명을 설정한 후 다음과 같은 함수에서 사용할 수 있습니다.
- sqlLib.connect()
- sqlLib.disconnect()
- sqlLib.beginDatabaseTransaction()
- sqlLib.setCurrentDatabase()
이 함수는 Java™ 생성에 대해서만 유효합니다.
구문
sqlLib.defineDatabaseAlias(
alias STRING in,
database STRING in)
- alias
- 두 번째 매개변수로 식별된 연결의 별명으로 동작하는 문자열 리터럴 또는 변수입니다. 별명은 대소문자를 구분하지 않습니다.
- database
- sqlLib.connect()에 지정된 데이터베이스 이름입니다. 문자 리터럴 또는 변수를 사용하십시오.
예제
다음 예제는 sqlLib.defineDatabaseAlias() 함수를 사용하여 두 개의 개별 데이터베이스 연결을 유지보수하는 방법을 보여줍니다.
// Connect to a database with alias "alias",
// which becomes the current connection.
defineDatabaseAlias( "alias", "database" );
connect( "alias", "user", "pwd" );
// Make two connections to the same database.
String db = "database";
defineDatabaseAlias( "alias1", db );
defineDatabaseAlias( "alias2", db );
connect( "alias1", "user", "pwd" );
connect( "alias2", "user", "pwd" );
// Another way to make two connections
// to the same database.
defineDatabaseAlias( "alias", "database" );
connect( "alias", "user", "pwd" );
connect( "database", "user", "pwd" );
// An alias is defined but not used. The second
// connect() does not create a new connection.
defineDatabaseAlias( "alias", "database" );
connect( "database", "user", "pwd" );
connect( "database", "user", "pwd" );
// Use of an alias (which is case-insensitive)
// when disconnecting.
defineDatabaseAlias( "alias", "database" );
connect( "aLiAs", "user", "pwd" );
disconnect( "ALIAS" );
// The next disconnect call fails because the
// connection is named "alias" not "database".
defineDatabaseAlias( "alias", "database" );
connect( "alias", "user", "pwd" );
disconnect( "database" );
// An alias can change. After the next call,
// "alias" refers to "firstDatabase"
defineDatabaseAlias( "alias", "firstDatabase" );
// After the next call,
// "alias" refers to "secondDatabase".
defineDatabaseAlias( "alias", "secondDatabase" );
// The last call would have failed
// if a connection were in place with "alias".
호환성
| 플랫폼 | 문제 |
|---|---|
| VisualAge® Generator 호환성 | vgLib.connectionService() 호출에서 데이터베이스 별명을 사용할 수 있습니다. |