PB开发笔记之Access+ODBC自动注册和发布[转贴]

来源:互联网 发布:明仁宗 知乎 编辑:程序博客网 时间:2024/04/29 16:05
1。代码如下:
string datafile,odbc_driver
int reg_result
integer odbc_init
odbc_init=profileint("system.ini","start","first",1)

ulong ul_n,ul_m
ul_n=25
ul_m=0
//第一次运行时进行注册
//if odbc_init= 1 then //如果等于1 则进行注册
//判断系统是否已经安装Access
string ls_sys,ls_install
ls_sys="HKEY_LOCAL_MACHINE/Software/ODBC/ODBCINST.INI/ODBC DRIVERS"
RegistryGet(ls_sys, "Microsoft Access Driver (*.mdb)", RegString!,ls_install)
if trim(ls_install)<> "Installed" then
messagebox("错误","未安装Microsoft Access Driver")
halt
end if

environment env // holds environment information
string startupfile // holds name of start-up file

/* Get the environment information */
IF ( GetEnvironment(env) <> 1 ) THEN
MessageBox( "Application: Open", "Unable to get environment information.~n Halting ..." )
HALT
END IF

/* Select start-up file by operating system */
CHOOSE CASE env.OSType
CASE Windows!
if directoryexists('c:/windows/System') then
odbc_driver="c:/windows/System/odbcjt32.dll"
elseif directoryexists('d:/windows/System') then
odbc_driver="d:/windows/System/odbcjt32.dll"
elseif directoryexists('e:/windows/System') then
odbc_driver="e:/windows/System/odbcjt32.dll"
elseif directoryexists('f:/windows/System') then
odbc_driver="f:/windows/System/odbcjt32.dll"
elseif directoryexists('g:/windows/System') then
odbc_driver="g:/windows/System/odbcjt32.dll"
else
messagebox('错误!','无法注册ODBC!')
halt
end if

case WindowsNT!
if directoryexists("c:/WINNT/System32") then
odbc_driver="c:/WINNT/System32/odbcjt32.dll"
elseif directoryexists("d:/WINNT/System32") then
odbc_driver="d:/WINNT/System32/odbcjt32.dll"
elseif directoryexists("e:/WINNT/System32") then
odbc_driver="e:/WINNT/System32/odbcjt32.dll"
elseif directoryexists("f:/WINNT/System32") then
odbc_driver="f:/WINNT/System32/odbcjt32.dll"
elseif directoryexists("g:/WINNT/System32") then
odbc_driver="g:/WINNT/System32/odbcjt32.dll"
else
messagebox('错误!','无法注册ODBC!')
halt close
end if

//CASE Sol2!, AIX!, OSF1!, HPUX!
//CASE Macintosh!
CASE ELSE
MessageBox( "错误!", "该软件只能在Windows或WindowsNT上运行!!" )
HALT close
END CHOOSE
//使用函数GetCurrentDirectory()得到当前目录
//与数据库文件名合并为一个字串变量后得到数据库文件所在路径
string ls_dir
ls_dir = GetCurrentDirectory()
if right(ls_dir,1) = '/' then
datafile = ls_dir + 'db1.mdb'
else
datafile = ls_dir + '/' + 'db1.mdb'
end if
reg_result =registryset("HKEY_CURRENT_USER/software/odbc/odbc.ini/odbc datasources","test1",regstring!,"Microsoft Access Driver (*.mdb)")
reg_result =registryset("HKEY_CURRENT_USER/software/odbc/odbc.ini/test1","",regstring!," ")
reg_result =registryset("HKEY_CURRENT_USER/software/odbc/odbc.ini/test1","DBQ",regstring!,datafile)
reg_result =registryset("HKEY_CURRENT_USER/software/odbc/odbc.ini/test1","driver",regstring!,odbc_driver)
reg_result =registryset("HKEY_CURRENT_USER/software/odbc/odbc.ini/test1","driverID",regulong!,ul_n)
reg_result =registryset("HKEY_CURRENT_USER/software/odbc/odbc.ini/test1","Fil",regstring!,"MS access;")
reg_result =registryset("HKEY_CURRENT_USER/software/odbc/odbc.ini/test1","safetransaction",regulong!,ul_m)
reg_result =registryset("HKEY_CURRENT_USER/software/odbc/odbc.ini/test1","uid",regstring!," ")
// setprofilestring("system.ini","start","first","0")
//end if
//ODBC 注册结束

// This script will read all the database values from PB.INI
// and store them in SQLCA.
//建立与数据库的连接
SQLCA.DBMS =ProfileString("test1.ini","Profile Brands Manage","DBMS", " ")
SQLCA.DbParm =ProfileString("test1.ini","Profile Brands Manage","DbParm", " ")
string ls_autocommit
ls_autocommit = ProfileString("test1.ini","Profile Brands Manage","AutoCommit", " ")
if Upper(ls_autocommit) = 'FALSE' then
SQLCA.autocommit = false
else
SQLCA.autocommit = true
end if

CONNECT USING SQLCA;
IF SQLCA.SQLCode = -1 THEN
MessageBox("连接数据库", " 不能连接到数据库上,请检查网络与用户名是否正确。~r~n出错的详细原因为:"+SQLCA.SQLErrText)
Halt Close
END IF
open(w_test)

2。其中system.ini文件在系统目录下,test1.ini的内容如下:
[Profile Brands Manage]
DBMS = "ODBC"
AutoCommit = False
DBParm = "ConnectString='DSN=test1;UID=;PWD='"

3。发布需要的文件有:
db1.mdb 数据文件
test1.exe 可执行文件
test1.ini
test1.dll
以及必须的支持文件
pbvm90.dll
libjcc.dll
libjsybheap.dll
pbdwe90.dll
pbodb90.dll :pb的ODBC接口文件
另外系统目录下必须有odbc驱动,系统必须安装有Access。 
 
原创粉丝点击