- UID
- 783195
- 积分
- 24
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2019-1-1
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2019-10-20 20:42:14
|
显示全部楼层
;;装好 sqliteodbcqudong_downcc
;;建好 sqlite3 的odbc Driver={SQLite3 ODBC Driver}
;;准备一个 test.db 文件 Database=I:\\A_slv\\db\\test.db;
;;表里有个 scb 字段有 dh,cp,sl,tuan
;;加几个记录
;;数据库连接函数ADOLISP,目前测试32位CAD可用(系统32位和64位均可)
;;; An example of using ADOLISP_Library.lsp
(if (not ADOLISP_ConnectToDB)
(load "ADOLISP_Library.lsp")
)
(defun C:sqltt (/ ConnectionObject Result ConnectString SQLStatement
TablesList ColumnsList
)
;; Connecting to the database ...
; (setq ConnectString
; "Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\CAD\\ADOLISP_test.mdb"
; )
;; An alternative connect string
;(setq ConnectString "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\CAD\\ADOLISP_test.mdb;Persist Security Info=False")
;(setq ConnectString "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\CAD\\ADOLISP_test.accdb;Persist Security Info=False")
(setq ConnectString
;; "DRIVER=Devart ODBC Driver for SQLite;Database=C:\\CAD\\test.db"
;;设定一个链接字符串
"Driver={SQLite3 ODBC Driver};Database=I:\\A_slv\\db\\test.db;
StepAPI=0;SyncPragma=;NoTXN=0;Timeout=;ShortNames=0;LongNames=0;NoCreat=0;NoWCHAR=0;
FKSupport=0;JournalMode=;OEMCP=0;LoadExt=;BigInt=0;JDConv=0;
"
)
;; 去连接
(prompt (strcat "\n\nConnecting to the database using \n\""
ConnectString
"\""
)
)
(if (not (setq ConnectionObject
(ADOLISP_ConnectToDB ConnectString "admin" "")
)
)
(progn
(prompt "\nConnection failed!")
(ADOLISP_ErrorPrinter)
)
(prompt "\nResult: succeeded!")
)
;; If we got a connection ...
;; 如果得到 链接
(if ConnectionObject
(progn
;; Retrieve some data
(setq
SQLStatement "SELECT * FROM scb"
)
(prompt
(strcat
"\n\nExecuting a SELECT statement to retrieve some data:\n\""
SQLStatement
"\""
)
)
(if (setq Result (ADOLISP_DoSQL ConnectionObject SQLStatement))
(progn
(prompt "\nResult: ")
(print Result)
)
(progn
(prompt "\nFailed!")
(ADOLISP_ErrorPrinter)
)
)
;; Insert a row
(setq SQLStatement
; "INSERT INTO DESKS (AUTOCAD_HANDLE, AUTOCAD_DRAWING, OCCUPANT, EXTENSION, PROPERTY_NUMBER) VALUES ('ABCDEF00', 'TESTDRAWING', 'Barbara', '123456', '654321')"
"INSERT INTO SCB (dh,cp,sl) VALUES ('15','柜子','18')"
)
(prompt (strcat "\n\nInserting a row:\n\""
SQLStatement
"\""
)
)
(if (setq Result (ADOLISP_DoSQL ConnectionObject SQLStatement))
(prompt "\nResult:\nSucceeded!")
(progn
(prompt "\nFailed!")
(ADOLISP_ErrorPrinter)
)
)
;; Change a row or rows
(setq SQLStatement
;"UPDATE DESKS SET OCCUPANT='Me' WHERE AUTOCAD_DRAWING='TESTDRAWING'"
"UPDATE SCB SET SL='9' WHERE tuan='中文'"
)
(prompt (strcat "\n\nChanging a row or rows:\n\""
SQLStatement
"\""
)
)
(if (setq Result (ADOLISP_DoSQL ConnectionObject SQLStatement))
(prompt "\nResult:\nSucceeded!")
(progn
(prompt "\nFailed!")
(ADOLISP_ErrorPrinter)
)
)
;; Delete a row or rows
|;
(setq SQLStatement
"DELETE FROM scb WHERE cp='柜子'"
)
(prompt (strcat "\n\nDeleting a row or rows:\n\""
SQLStatement
"\""
)
)
(if (setq Result (ADOLISP_DoSQL ConnectionObject SQLStatement))
(prompt "\nResult:\nSucceeded!")
(progn
(prompt "\nFailed!")
(ADOLISP_ErrorPrinter)
)
)
;; Just for grins, see what's in the database
(prompt "\n\nTables and views in the database:")
(setq TablesList (ADOLISP_GetTablesAndViews ConnectionObject))
(print (ADOLISP_GetTablesAndViews ConnectionObject))
(prompt (strcat "\n\nColumn properties in table "
(caar TablesList)
":"
)
)
(setq ColumnsList
(ADOLISP_GetColumns
ConnectionObject
(caar TablesList)
)
)
(foreach Item ColumnsList
(print Item)
)
|;
;; Disconnect 断开链接
(prompt "\n\nDisconnecting from the database\n")
(ADOLISP_DisconnectFromDB ConnectionObject)
;; Although the following is unnecessary in this case (because
;; ConnectionObject is a local variable), it's never a _bad_
;; idea to NIL-out the connection object.
(setq ConnectionObject nil)
|;
)
)
(prin1)
)
(prin1) |
|