本地monetdb客户端python api

python-monetdb的Python项目详细描述


简介

这是新的本地python客户端api。这个api是跨平台的, 也不依赖于任何monetdb库。它支持 python 2.5+与python dbapi 2.0兼容。

折旧警告

python monetdb被pymonetdb替换。python monetdb不会 接收更多更新。请切换到pymonetdb,它应该 作为替补。只更改导入语句 import monetdbimport pymonetdb

安装

要安装monetdb python api,请从 python源目录:

# python setup.py install

仅此而已,现在您可以开始使用api了。

文档

python代码有很好的文档记录,因此如果需要 文档您应该看看源代码。下面是 关于如何使用monetdb sql api的交互式示例 你起步很快。

运行测试套件

安装tox并在根目录中运行tox。

您可以使用环境变量控制测试行为:

* MAPIPORT - what port is MonetDB running? _50000_ by default
* TSTHOSTNAME -  where is MonetDB running? _localhost_ by default
* TSTPASSPHRASE - what passphrase to test control command? _testdb_ by default
* TSTDB -  what database to use for testing? _demo_ by default
* TSTUSERNAME - username, _monetdb_ by default
* TSTPASSWORD - password, _monetdb_ by default

注意,首先需要创建并启动monetdb数据库。如果你 要运行控制测试,需要设置密码短语并设置control=true。

示例

“examples”文件夹中有一些示例,但下面是 SQL API的逐行示例:

> # import the SQL module
> import monetdb.sql
>
> # set up a connection. arguments below are the defaults
> connection = monetdb.sql.connect(username="monetdb", password="monetdb", hostname="localhost", database="demo")
>
> # create a cursor
> cursor = connection.cursor()
>
> # increase the rows fetched to increase performance (optional)
> cursor.arraysize = 100
>
> # execute a query (return the number of rows to fetch)
> cursor.execute('SELECT * FROM tables')
26
>
> # fetch only one row
> cursor.fetchone()
[1062, 'schemas', 1061, None, 0, True, 0, 0]
>
> # fetch the remaining rows
> cursor.fetchall()
[[1067, 'types', 1061, None, 0, True, 0, 0],
 [1076, 'functions', 1061, None, 0, True, 0, 0],
 [1085, 'args', 1061, None, 0, True, 0, 0],
 [1093, 'sequences', 1061, None, 0, True, 0, 0],
 [1103, 'dependencies', 1061, None, 0, True, 0, 0],
 [1107, 'connections', 1061, None, 0, True, 0, 0],
 [1116, '_tables', 1061, None, 0, True, 0, 0],
 ...
 [4141, 'user_role', 1061, None, 0, True, 0, 0],
 [4144, 'auths', 1061, None, 0, True, 0, 0],
 [4148, 'privileges', 1061, None, 0, True, 0, 0]]
>
> # Show the table meta data
> cursor.description
[('id', 'int', 4, 4, None, None, None),
 ('name', 'varchar', 12, 12, None, None, None),
 ('schema_id', 'int', 4, 4, None, None, None),
 ('query', 'varchar', 168, 168, None, None, None),
 ('type', 'smallint', 1, 1, None, None, None),
 ('system', 'boolean', 5, 5, None, None, None),
 ('commit_action', 'smallint', 1, 1, None, None, None),
 ('temporary', 'tinyint', 1, 1, None, None, None)]

如果您想与较低级别的数据库通信 您可以使用MAPI库:

> from monetdb import mapi
> server = mapi.Server()
> server.connect(hostname="localhost", port=50000, username="monetdb", password="monetdb", database="demo", language="sql")
> server.cmd("sSELECT * FROM tables;")
...

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java CXF和授权   java在网站中部署使用swing创建的表单   java为什么getHeaderField()返回一个字符串,其中getHeaderFields()返回HttpUrlConnection中的Map<String,List<String>>   java如何检测恶意数据包?   webview中的java网页为空   java SWT图像资源,用于将我的所有图像存储在一个位置   java计算数组的最大长度,使平均值小于给定值   java“发件人电话号码无效”和美国号码   将Swing组件作为内容的自定义Java工具提示不会显示   在并发HashMap中重新灰化期间的java检索   Java 7和Tomcat 7.0.64 ClassFormatException:常量池中的字节标记无效   使用JUnit的java assertNull因NullPointerException失败   java内存中的文件是否与文件系统中的文件大小相同?   循环内实例化的类型的java注入依赖项