执行sqlite3的“点”来自Python的命令或在命令行实用工具中注册排序规则 [英] Execute sqlite3 "dot" commands from Python or register collation in command line utility

查看:200
本文介绍了执行sqlite3的“点”来自Python的命令或在命令行实用工具中注册排序规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的sqlite3数据库包含一个 collat​​e列约束。我将其放在表的架构中,以防止意外忽略使用必要的排序规则。但这意味着从命令行而不是从我的Python代码运行 sqlite3 时,模式中引用的排序规则不存在,并且我无法使用点命令

My sqlite3 database contains a "collate" column-constraint. I've placed it in the schema for the table, to prevent accidentally neglecting to use the necessary collation. However this means when running sqlite3 from the command line, and not from my Python code, the collation referenced in the schema is not present, and I'm unable to use dot commands.

sqlite> .import data.txt table_name
Error: no such collation sequence: my_collation

此外,创建从Python连接,并添加所需的排序规则会遇到以下问题:

Furthermore, creating the connection from Python, and adding the collation required runs into this problem:

connWithCollation.execute(".import data.txt table_name")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
sqlite3.OperationalError: near ".": syntax error

execute 函数似乎不想传递sqlite3点命令。

The execute function it would appear does not want to pass the sqlite3 dot command through.

在必要的整理功能时如何执行sqlite3点命令不存在?或者,如何从Python执行sqlite3点命令?

How can I execute sqlite3 dot commands when necessary collation functions are not present? Alternatively, how can I execute sqlite3 dot commands from Python?

推荐答案

您可以使用 load_extension()内置SQLite函数或。load 命令。显然,扩展名是用C编写的。

You can load new collating sequences and functions using load_extension() built-in SQLite function or .load command in command line shell for SQLite. Obviously, extensions shold be written in C.

而且您不能从python调用点命令,因为点命令特定于命令行外壳工具。

And you can not call dot-commands from python, because dot-commands are specific to the command line shell tool.

这篇关于执行sqlite3的“点”来自Python的命令或在命令行实用工具中注册排序规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆