Poweruilder 12.6 中的动态 SQL

Dynamic SQL in Poweruilder 12.6

我在 Powerbuilder 12.6 中使用 Dynamic SQL 创建了一个函数如下,数据库是 SQL Anywhere 10.0

// function name :of_encrypt()
// parameters: string as_info, as_passwd

String ls_sql
blob lblb_encrypted

// two types all report error message
// there are two parameters in the SQL.
//ls_sql = "select encrypt('?','?')" // add apostrophe
ls_sql = "select encrypt(?,?)"       // not apostrophe

DECLARE C1 DYNAMIC CURSOR FOR SQLSA;
PREPARE SQLSA FROM :ls_sql;
OPEN DYNAMIC C1 USING :as_info,:as_passwd;  // this line reported error, not allowed two parameters?
FETCH C1 INTO :lblb_encrypted;
CLOSE C1;
Return lblb_encrypted

我用这个函数测试后如下:

of_encrypt("software","passwd")

Powerbuilder 给出错误信息:

Error:Database command not successfully prepared at line 13 in function of_encrypt.

如何查找错误?

我只见过用于指示数据库事务对象的 USING 语句,所以我想知道这是否是一个问题。

我认为这样的方法可能有效:

ls_sql = "select encrypt('" + as_info + "','" + as_passwd + "')"     

DECLARE C1 DYNAMIC CURSOR FOR SQLSA;
PREPARE SQLSA FROM :ls_sql;
OPEN DYNAMIC C1;
FETCH C1 INTO :lblb_encrypted;
CLOSE C1;

或者如果您不需要动态 sql:

SELECT  encrypt(:as_info , :as_passwd)
INTO        :lblb_encrypted
FROM        dummy;

使用 SELECTBLOB

    Blob lblb_encrypted
    string as_info, as_passwd
    SELECTBLOB encrypt(:as_info, :as_passwd) INTO :lblb_encrypted FROM table;