本帖最后由 dcl1214 于 2025-9-14 11:39 编辑
如果希望速度快,标准化,cad excel word 等等软件都能交互,建议还是用odbc方案,见我的其它帖子

网友答: 试了一下,没有path这个变量对应的内容网友答:
不好意思,手误 ,改了,你试试网友答: 麻烦上传个sqlite3.exe网友答: 这个方法能交互mdb吗网友答:
zip文件里面就有网友答: 这也就是查询个字符串类型的数据。select *意味着选择了所有,是否还需要进一步过滤?如果要,后继还得在lisp中处理。
这样搞数据库的方式远不如直接在lisp中用字典存贮数据,不但支持字符串,还支持其他数据类型。
如果希望速度快,标准化,cad excel word 等等软件都能交互,建议还是用odbc方案,见我的其它帖子

- (defun c:tt ()
- (setq exe-path "C:\\test\\sqlite3.exe")
- (setq db-path "C:\\test\\123.db")
- (setq outPath "C:\\test\\out.txt")
- (setq sql "select * from test")
- (setq psFile (vl-filename-mktemp (strcat path "query.ps1")))
- (setq file (open psfile "w"))
- (foreach cmd
- (list
- (strcat "$sqlitePath = \"" exe-path "\"")
- (strcat "$dbPath = \"" db-path "\"")
- (strcat "$sqlquery = \"" sql "\"")
- (strcat "$outPath = \"" outPath "\"")
- "$oldEncoding = [Console]::OutputEncoding"
- "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8"
- "$output = & $sqlitePath $dbPath $sqlquery"
- "if (-not $output) {exit 0}"
- "$outputString = $output -join \"`r`n\""
- "$utf8Bytes = [System.Text.Encoding]::UTF8.GetBytes($outputString)"
- "$gbkBytes = [System.Text.Encoding]::Convert([System.Text.Encoding]::UTF8,[System.Text.Encoding]::GetEncoding(936),$utf8Bytes)"
- "[System.IO.File]::WriteAllBytes($outPath , $gbkBytes)"
- "Write-Host 'OK.'"
- "[Console]::OutputEncoding = $oldEncoding"
- )
- (write-line cmd file)
- )
- (close file)
- (setq wsh (vlax-create-object "wscript.shell"))
- (setq
- pscode (strcat "powershell.exe -ExecutionPolicy Bypass -File "
- psFile
- )
- )
- (vlax-invoke wsh 'Run pscode 0 1)
- ;;此种方法不弹窗
- (vlax-release-object wsh)
- ;;下面读取txt是lisp的事情了
- (setq file (open outPath "r"))
- (setq lst nil)
- (while (setq str (read-line file))
- (setq lst (cons str lst))
- )
- (close file)
- ;;删除临时文件
- (vl-file-delete outPath)
- (vl-file-delete psfile)
- ;;list表要翻转
- (reverse lst)
- )
网友答: 试了一下,没有path这个变量对应的内容网友答:
烟盒迷唇 发表于 2025-9-14 11:23
试了一下,没有path这个变量对应的内容
不好意思,手误 ,改了,你试试网友答: 麻烦上传个sqlite3.exe网友答: 这个方法能交互mdb吗网友答:
crtrccrt 发表于 2025-9-15 19:15
麻烦上传个sqlite3.exe
zip文件里面就有网友答: 这也就是查询个字符串类型的数据。select *意味着选择了所有,是否还需要进一步过滤?如果要,后继还得在lisp中处理。
这样搞数据库的方式远不如直接在lisp中用字典存贮数据,不但支持字符串,还支持其他数据类型。