複数のクエリを実行するスクリプトがあります。だから私の顧客は“ Open Database()”コマンドが呼ばれる度にDSNを選ばなければならなかった。そこで私はこの問題を解決するための関数を書きました。ユーザーがDSN文字列を選択したときにそれを傍受し、それを変数に保存します。その後、私のスクリプトは、ユーザーが再選択しなくてもDSNに後でアクセスできます。
/*
Function
to intercept user's DSN
selection through ODBC interface for database queries.
This is useful for scripts that
run Open Database() multiple times on the same database.
Opens user's Windows ODBC to allow them to select a DSN.
Returns the DSN string to query the database. If fail, it pops up
a window indicating the error, and returns empty string.
Arguments:
_test_query_:
A very simple query that will return a SQL error if
user
selected wrong DSN. It
will return a
results table if there is no error.
_database_:
The name of the database for the error window.
Local
Variables:
_DSN_test_:
temporary table that will contain the table variable with DSN
_DSN_string_:
string extracted from Database query results Table Variable "JSL"
Example
usage:
DSN_setup("SELECT
TOP 1 * FROM dbo.Dim_DiePV","NSGTestDW");
*/
::DSN_setup = Function(
//Arguments
{_test_query_, _database_},
//Locals
{_DSN_test_, _DSN_string_},
_DSN_test_ =
Open Database( , _test_query_ );
If( Char( _DSN_test_ ) == ".",
New Window( "Script Error",
<<MODAL></MODAL>それを指摘してくれてありがとう、 @JensRiege 。
私はそれを片付けました。