[求助]如何嵌入SQL
那为高手告知如何在LISP中嵌入SQL语句。还是根本就不可能,只能在VB 与C++在C++中怎样嵌入。与C一样吗? EXEC SQL吗? lisp我想应该不行的,因为他不支持activex,但Vlisp是可以的,下面是我以前写得一个程序,当时测试过了的,
;;;下面的这个函数是用来加载ado库的函数,已经测试成功
(vl-load-com)
(defun ado:initado (/ adopath)
(if (null adom-append)
(progn
(setq
adopath (strcat (getenv "systemdrive")
"\\Program Files\\Common Files\\System\\Ado\\"
)
)
(if (findfile (strcat adopath "msado15.dll"))
(vlax-import-type-library
:tlb-filename
(strcat adopath "msado15.dll")
:methods-prefix
"adom-"
:properties-prefix
"adop-"
:constants-prefix
"adoc-"
)
(alert "没有在指定的路径发现ado库文件")
)
)
)
)
;;;下面这个函数是一个用来执行查询命令的函数,接受一个字符串(sql查询语)
;;;然后返回一个记录集,如果是修改查询的话,则返回T
(defun ado:execute_sql (sqltxt tag /
connect_objconnect_strrecordset
affectlinesrepeat_num dispstr
thereturn
)
(setq connect_obj (vlax-create-object "adodb.connection"))
(setq connect_str "DSN=northwind_test;UID=sa;PWD=800513")
(adop-put-connectiontimeout connect_obj 40)
(adom-open connect_obj connect_str
"sa" "noguess"
adoc-adconnectunspecified
)
(if tag
(progn
(setq recordset (vlax-create-object "adodb.recordset"))
(adom-open recordset sqltxt
connect_obj adoc-adOpenkeyset
adoc-adLockOptimistic
-1
)
(setq thereturn recordset)
)
(progn
(adom-execute connect_obj sqltxt affectedlines adoc-adCmdUnknown)
(setq thereturn T)
)
)
(setq thereturn thereturn)
)
;;;下面的函数是主函数,其中引用了前面声明的函数
;;;函数的功能是将一个dwg文件中的所有具有 "HOUSE"
;;;扩展应用程序名的实体中的扩展数据入库道SQL数据库中,
;;;这个例子的表中就有两个字段"type"和"area".
(defun ado:input_database(/ ss ss_len xdata_list repeatnum j i area htype)
(ado:initado)
(setq ss (ssget "x" '((-3 ("HOUSE")))))
(setq ss_len (sslength ss) i 0)
(repeat ss_len
(setq xdata_list (cdr(assoc '-3 (entget (ssname ss i) '("HOUSE")))))
(setq repeatnum (length xdata_list) j 0)
(repeat repeatnum
(if (= (car (nth j xdata_list)) "HOUSE")
(progn
(setq area (cdr (assoc '1040 (cdr(nth j xdata_list)))))
(setq htype (cdr (assoc '1000 (cdr(nth j xdata_list)))))
)
)
(setq j (1+ j))
)
(ado:execute_sql (strcat "insert into house_info (type,area) values ('" htype "'," (rtos area 2 2) ")") nil)
(setq i (1+ i))
)
(alert "房屋扩展数据入库成功")
)
;;;这个函数是用来显示数据库中的相关房子的信息,当数据库信息保存道一定的量,
;;;可以用Vlisp程序来根据信息出DWG图形,其实,DWG文件就是一个数据库,稍微知道
;;;一点ARX的就可以知道,看看版主leeyeafu写的连载一吧,前面的部分可能会让
;;;你豁然开朗.
(defun ado:disp_database(/ recordset repeat_num dispstr )
(setq recordset (ado:execute_sql "select * from house_info order by right(type,4)" T))
(setq repeat_num (adop-get-recordcount recordset))
(setq dispstr "")
(repeat repeat_num
(setq
dispstr
(strcat
dispstr
"\n"
(vlax-variant-value(adop-get-value (adop-get-item (adop-get-fields recordset) "type"))) "\t"
(rtos (vlax-variant-value(adop-get-value (adop-get-item (adop-get-fields recordset) "area"))) 2 2)
)
)
(if (/= (adop-get-eof recordset) t)
(adom-movenext recordset)
)
)
(alert dispstr)
)
相关说明:
程序中所建立的表house_info放在数据库northwind数据库中
请自己创建一个odbc连接,能顺利连接到northwind数据库就可以了, 非常感谢您的指点 <p><font color="#1a42e6">(adom-open connect_obj connect_str<br/> "sa" "noguess"<br/> adoc-adconnectunspecified<br/> )</font></p><p>运行到这句时出现<font color="#ee3d11">; 错误: Automation 错误。 操作已被取消。</font><font color="#000000">请问是什么问题?<br/></font></p>
页:
[1]