我在我的一个 win 表单项目中使用 C# & Firebird SQL db。在表单中,我在 firebird db 中创建一个表,其中一个字段“id”作为身份/自动增量字段。我的代码是
private void createOrLoadGIIR(int pid, int tid,int mid)
{
string qryStrCL1 = @"EXECUTE BLOCK AS BEGIN
if (not exists(select 1 from rdb$relations where rdb$relation_name = 'loc_soningqp')) then
execute statement 'CREATE TABLE loc_soningqp (
q_r_id integer NOT NULL,
q_r_seccd varchar(5) NOT NULL,
q_r_subseccd varchar(5) NOT NULL,
q_r_direction blob,
q_r_desc blob NOT NULL,
q_r_caopt1 smallint DEFAULT 0,
q_r_caopt2 smallint DEFAULT 0,
q_r_caopt3 smallint DEFAULT 0,
q_r_caopt4 smallint DEFAULT 0,
q_r_caopt5 smallint DEFAULT 0,
q_r_sol blob,
q_r_difficulty varchar(10) DEFAULT NULL,
id integer NOT NULL,
PRIMARY KEY (id)
);';
CREATE GENERATOR gen_loc_soningqp_id;
CREATE TRIGGER loc_soningqp_bi FOR loc_soningqp
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.id IS NULL) THEN
NEW.id = GEN_ID(gen_loc_soningqp_id,1);
END^
END";
try
{
using (FbConnection conCL1 = new FbConnection(connectionString))
{
conCL1.Open();
using (FbCommand cmdCL1 = new FbCommand(qryStrCL1, conCL1))
{
cmdCL1.CommandType = CommandType.Text;
using (FbDataReader rdrCL1 = cmdCL1.ExecuteReader())
{
if (rdrCL1 != null)
{
//some code
}
}
}// command disposed here
} //connection closed and disposed here
}
catch (FbException ex)
{
//table exists
MessageBox.Show(ex.Message);
}
}
当我运行代码时,它会在 CREATE GENERATOR 行附近生成一个错误,说“CREATE 是一个未知令牌”。请告知我的代码有什么问题。我还想知道是否可以在执行块中创建存储过程。