使用sql文件动态建表的问题

ForDB 2004-02-27 06:48:03
以下是我用sql文件建表的代码,表老是建不上,不明白为什么,请高手指点。
代码如下:

//begin--check data
//begin ---create db object
string s_fileName
long l_fileLength
int i_fileNo
long l_number
string s_sql
string s_sqlfile="D:\Documents and Settings\Administrator\My Documents\aa.sql"
//DISCONNECT USING sqlca_master;
//create new trans object
tr_newBase = create transaction
tr_newBase.DBMS = "MSS Microsoft SQL Server 6.x"
tr_newBase.Database = "bb"
tr_newBase.LogPass = "yu"
tr_newBase.ServerName ="yu"
tr_newBase.LogId = "sa"
tr_newBase.AutoCommit = False
tr_newBase.DBParm = ""
connect using tr_newBase;
if tr_newBase.sqlcode <> 0 then
MessageBox ("数据库连接错误","不能连接到SQL Server数据库。请确认SQL Server数据库是否启动。~n~r"+"错误信息:" + tr_newBase.sqlerrtext ,stopSign!)
return
end if
//end create new trans...

//begin --get script file
s_fileName = s_sqlfile
l_fileLength = FileLength(s_fileName)
if l_fileLength > 32765 then
msg("脚本文件太大!")
DISCONNECT USING tr_newBase;
return
elseif l_fileLength > 0 then
//读取文件内容,执行动态SQL语句
i_fileNo = FileOpen(s_fileName, StreamMode!, Read!, LockRead!)
l_number = FileRead(i_fileNo, s_sql)
if l_number > 0 and l_number <= 32765 then
tr_newBase.AutoCommit = True
EXECUTE IMMEDIATE :s_sql
Using tr_newBase;
tr_newBase.AutoCommit = False
end if
FileClose(i_fileNO)
else //不能正确读取文件信息
sle_script.setFocus()
sle_script.SelectText(1,len(sle_script.text))
Msg("请输入正确的表结构脚本文件名称")
DISCONNECT USING tr_newBase;
return
end if
//end --get script file
//end
msg("成功!")
//====================================================
其中sql文件中表的代码如下:
create table xz_tj_all
( gxjg char(4) not null,
nian smallint not null,
yue tinyint not null,
bz1 tinyint not null,
bz2 tinyint not null,
a1 integer ,
a2 integer ,
a3 integer ,
primary key (gxjg, nian, yue, bz1, bz2)
)
create table xz_tj_4_1
( gxjg char(4) not null,
nian smallint not null,
yue tinyint not null,
bz1 tinyint not null,
bz2 tinyint not null,
a1 integer ,
primary key (gxjg, nian, yue, bz1, bz2)
)
//========================================================
顺便问一下,从sql文件中读到s_sql变量里的字符串是否是合法的sql字符串,又如何能测试出来??
...全文
91 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复

还没有回复,快来抢沙发~

相关推荐
发帖
PowerBuilder
创建于2007-09-28

866

社区成员

PowerBuilder 相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-02-27 06:48
社区公告
暂无公告