本帖最后由 dcl1214 于 2025-9-14 11:39 编辑


如果希望速度快,标准化,cad  excel  word  等等软件都能交互,建议还是用odbc方案,见我的其它帖子
  1. (defun c:tt ()
  2.   (setq exe-path "C:\\test\\sqlite3.exe")
  3.   (setq db-path "C:\\test\\123.db")
  4.   (setq outPath "C:\\test\\out.txt")
  5.   (setq sql "select * from test")
  6.   (setq psFile (vl-filename-mktemp (strcat path "query.ps1")))
  7.   (setq file (open psfile "w"))
  8.   (foreach cmd
  9.      (list
  10.        (strcat "$sqlitePath = \"" exe-path "\"")
  11.        (strcat "$dbPath = \"" db-path "\"")
  12.        (strcat "$sqlquery = \"" sql "\"")
  13.        (strcat "$outPath = \"" outPath "\"")
  14.        "$oldEncoding = [Console]::OutputEncoding"
  15.        "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8"
  16.        "$output = & $sqlitePath $dbPath $sqlquery"
  17.        "if (-not $output) {exit 0}"
  18.        "$outputString = $output -join \"`r`n\""
  19.        "$utf8Bytes = [System.Text.Encoding]::UTF8.GetBytes($outputString)"
  20.        "$gbkBytes = [System.Text.Encoding]::Convert([System.Text.Encoding]::UTF8,[System.Text.Encoding]::GetEncoding(936),$utf8Bytes)"
  21.        "[System.IO.File]::WriteAllBytes($outPath , $gbkBytes)"
  22.        "Write-Host 'OK.'"
  23.        "[Console]::OutputEncoding = $oldEncoding"
  24.      )
  25.     (write-line cmd file)
  26.   )
  27.   (close file)
  28.   (setq wsh (vlax-create-object "wscript.shell"))
  29.   (setq
  30.     pscode (strcat "powershell.exe  -ExecutionPolicy Bypass -File "
  31.        psFile
  32.      )
  33.   )
  34.   (vlax-invoke wsh 'Run pscode 0 1)
  35.   ;;此种方法不弹窗
  36.   (vlax-release-object wsh)
  37.   ;;下面读取txt是lisp的事情了
  38.   (setq file (open outPath "r"))
  39.   (setq lst nil)
  40.   (while (setq str (read-line file))
  41.     (setq lst (cons str lst))
  42.   )
  43.   (close file)
  44.   ;;删除临时文件
  45.   (vl-file-delete outPath)
  46.   (vl-file-delete psfile)
  47.   ;;list表要翻转
  48.   (reverse lst)
  49. )



网友答: 试了一下,没有path这个变量对应的内容

网友答:
烟盒迷唇 发表于 2025-9-14 11:23
试了一下,没有path这个变量对应的内容

不好意思,手误 ,改了,你试试

网友答: 麻烦上传个sqlite3.exe

网友答: 这个方法能交互mdb吗

网友答:
crtrccrt 发表于 2025-9-15 19:15
麻烦上传个sqlite3.exe

zip文件里面就有

网友答: 这也就是查询个字符串类型的数据。select *意味着选择了所有,是否还需要进一步过滤?如果要,后继还得在lisp中处理。
这样搞数据库的方式远不如直接在lisp中用字典存贮数据,不但支持字符串,还支持其他数据类型。
  • 上一篇:<<<**** 簡易多功能dcl創建+參數式轉lisp檔
  • 下一篇:没有了