水平所限,有很多不准确的地方。

原文在这里:http://www.firebirdsql.org/file/documentation/drivers_documentation/python/fdb/getting-started.html#quick-start-guide

firebird 的 python 驱动下载地址:https://pypi.org/project/fdb/#files

安装步骤:

——————————————————————————————————————

FDB 是基于Firebird客户端库文件(fbclient.so/dll),用ctypes写的纯python模块,因此,安装FDB前,要确保firebird客户端正确安装。FDB支持Firebird 2.0及以上版本。

FDB作为setuptools包分发,所以,需要先安装 setuptools 或者 compatible package。

从PYPI安装:

——————————————————————————————————————

运行easy_install 或 pip:

$ pip install fdb

或者:

$ easy_install fdb

从源码安装:

——————————————————————————————————————

下载,解压缩,然后运行安装命令

$ curl -O http://pypi.python.org/packages/source/f/fdb/fdb-0.9.1.tar.gz
$ tar -xzvf fdb-0.9.1.tar.gz
$ cd fdb-0.9.1
$ python setup.py install

快速开始:

——————————————————————————————————————

本文仅仅演示一些基本的功能。

数据库连接:

例1:

建立一个典型的数据库连接。

import fdb# The server is named 'bison'; the database file is at '/temp/test.db'.
con = fdb.connect(dsn='bison:/temp/test.db', user='sysdba', password='pass')# Or, equivalently:
con = fdb.connect(host='bison', database='/temp/test.db',user='sysdba', password='pass')

例2:

假设我们想要用 SQL Dialect 1,以及指定用 UTF-8 编码:

import fdbcon = fdb.connect(dsn='bison:/temp/test.db',user='sysdba', password='pass',dialect=1, # necessary for all dialect 1 databasescharset='UTF8' # specify a character set for the connection)

执行sql语句:

For this section, suppose we have a table defined and populated by the following SQL code:

本部分,假设我们已经定义了一张表,并且使用如下的 sql 代码写入数据:

create table languages
(name               varchar(20),year_released      integer
);insert into languages (name, year_released) values ('C',        1972);
insert into languages (name, year_released) values ('Python',   1991);

例1:

显示表中的所有内容:

import fdbcon = fdb.connect(dsn='/temp/test.db', user='sysdba', password='masterkey')# Create a Cursor object that operates in the context of Connection con:
cur = con.cursor()# Execute the SELECT statement:
cur.execute("select * from languages order by year_released")# Retrieve all rows as a sequence and print that sequence:
print cur.fetchall()

例2:

演示了取得每次提取一行数据的多种方法。

import fdbcon = fdb.connect(dsn='/temp/test.db', user='sysdba', password='masterkey')cur = con.cursor()
SELECT = "select name, year_released from languages order by year_released"# 1. Iterate over the rows available from the cursor, unpacking the
# resulting sequences to yield their elements (name, year_released):
cur.execute(SELECT)
for (name, year_released) in cur:print '%s has been publicly available since %d.' % (name, year_released)# 2. Equivalently:
cur.execute(SELECT)
for row in cur:print '%s has been publicly available since %d.' % (row[0], row[1])# 3. Using mapping-iteration rather than sequence-iteration:
cur.execute(SELECT)
for row in cur.itermap():print '%(name)s has been publicly available since %(year_released)d.' % row

例3:

简化的表格打印。

import fdbTABLE_NAME = 'languages'
SELECT = 'select * from %s order by year_released' % TABLE_NAMEcon = fdb.connect(dsn='/temp/test.db', user='sysdba', password='masterkey')cur = con.cursor()
cur.execute(SELECT)# Print a header.
for fieldDesc in cur.description:print fieldDesc[fdb.DESCRIPTION_NAME].ljust(fieldDesc[fdb.DESCRIPTION_DISPLAY_SIZE]) ,
print # Finish the header with a newline.
print '-' * 78# For each row, print the value of each field left-justified within
# the maximum possible width of that field.
fieldIndices = range(len(cur.description))
for row in cur:for fieldIndex in fieldIndices:fieldValue = str(row[fieldIndex])fieldMaxWidth = cur.description[fieldIndex][fdb.DESCRIPTION_DISPLAY_SIZE]print fieldValue.ljust(fieldMaxWidth) ,print # Finish the row with a newline.

例4:

插入数据。

import fdbcon = fdb.connect(dsn='/temp/test.db', user='sysdba', password='masterkey')cur = con.cursor()newLanguages = [('Lisp',  1958),('Dylan', 1995),]cur.executemany("insert into languages (name, year_released) values (?, ?)",newLanguages)# The changes will not be saved unless the transaction is committed explicitly:
con.commit()

注意上面的参数化sql语句。当执行重复的语句,这种方式比手工组合sql语句速度更快,更不易出错。参考: Prepared Statements.

运行例4后,再运行例3。结果会是这样:

NAME                 YEAR_RELEASED
------------------------------------------------------------------------------
Lisp                 1958
C                    1972
Python               1991
Dylan                1995

调用存储过程:

更多内容,请看原文......

python的Firebird驱动:FDB使用说明相关推荐

  1. Python 中 concurrent.futures 模块使用说明

    Python 中 concurrent.futures 模块使用说明 转载请注明出处:https://blog.csdn.net/jpch89/article/details/87643972 文章目 ...

  2. 学习OceanBase|OB-ODBC 驱动和 MySQL 官方 MySQL-ODBC 驱动的使用说明和配置方法

    本文介绍了 OceanBase 数据库的 OB-ODBC 驱动和 MySQL 官方 MySQL-ODBC 驱动的使用说明和配置方法. 开放数据库互连(ODBC)是微软公司开放服务结构( WOSA,Wi ...

  3. python编写打印机驱动_python驱动打印机-女性时尚流行美容健康娱乐mv-ida网

    女性时尚流行美容健康娱乐mv-ida网 mvida时尚娱乐网 首页 美容 护肤 化妆技巧 发型 服饰 健康 情感 美体 美食 娱乐 明星八卦 首页  > 高级搜索 喷墨 打印 机 墨盒使用的技巧 ...

  4. 2021-05-24 Hikvision DS-TVL224-4-5Y Python 显示部分驱动代码

    Hikvision DS-TVL224-4-5Y Python 显示部分驱动代码 import socket from threading import Threadthread_lock = Fal ...

  5. python+unity表情驱动一

    python+unity表情驱动工具一 引言 ui界面 python代码 所需资源 引言 最近看到一个视频关于python控制unity人物表情的视频,大体思路是使用python控制摄像头进行人脸识别 ...

  6. python+unity表情驱动二(打包成exe)

    python+unity表情驱动工具二(打包成exe) 使用pyinstaller在控制台打包 工具的使用效果 使用pyinstaller在控制台打包 这里并没有使用auto-py-to-exe界面工 ...

  7. python调用打印机驱动下载_selenium的Python使用(一)浏览器驱动的安装及使用

    一.selenium的安装 直接使用pip进行安装 pip install selenium    #(安装最新版本) pip install selenium==3.6.0   #(安装指定版本) ...

  8. 案例驱动python编程入门-用Python进行行为驱动开发的入门教程

    为驱动开发(Behavior-Driven Development,BDD)是一种卓越的开发模式.能帮助开发者养成日清日结的好习惯,从而避免甚至杜绝"最后一分钟"的情况出现,因此对 ...

  9. python可以开发驱动吗_Python机器学习实践:测试驱动的开发方法

    Python机器学习实践:测试驱动的开发方法 作者:(美)马修·柯克(Matthew Kirk) 著 出版日期:2017年10月 文件大小:30.91M 支持设备: ¥40.00在线试读 适用客户端: ...

最新文章

  1. 基于级联FFT的广义互相关算法在声源定位中的应用
  2. 期末复习、化学反应工程科目(第五章)
  3. 安装cuda 非root_linux非root用户下安装软件,搭建生产环境
  4. PAM+4+matlab,基于PAM4调制的400G光模块
  5. 学习笔记3 :pyqt5 显示opencv 和 PIL图片
  6. python多目标跟踪卡尔曼滤波_卡尔曼多目标跟踪的例子?
  7. 今晚直播丨有备无患 - 达梦8的备份恢复
  8. myeclipse需要配置服务器得项目是,【SpringMVC】使用Myeclipse创建SpringMVC项目【超详细教程】...
  9. java写龟兔赛跑_有关JAVA编写龟兔赛跑的游戏的问题。求助……
  10. Android 缓存处理和图片处理
  11. java如何中断父类方法_java – 如何测试调用父类的受保护(不需要)方法的方法?...
  12. shell之任务控制
  13. 目前微型计算机硬件主要采用,目前使用的微型计算机硬件主要采用的电子器件是()。 A. 真空管 B. 晶体管 C. 大规模和超大规模集成电路...
  14. 编译Libtorrent
  15. 计组实验-CPU设计-指令添加
  16. win7桌面上的ie图标删不掉怎么办
  17. Unity3D游戏引擎最详尽基础教程
  18. 数据分析的重要性体现在哪?
  19. LeetCode知识点总结 - 2073
  20. nginx多域名重定向到不同的二级域名

热门文章

  1. linux学习2shell脚本编程案例
  2. R软件与RStudio安装(版本R-4.2.2)Windows10
  3. 跨时钟域电路设计方法
  4. python解析pdf文件
  5. 18大学计算机基础,最新大学计算机基础试题及答案完整版(18页)-原创力文档...
  6. 【Spring Boot】 过滤器、监听器、拦截器的使用
  7. 君のことが好きだよ。
  8. 基于jsp+servlet的javaweb实现最基本的用户注册登陆注销功能
  9. awt绘图应用--桌上弹球
  10. php 输出时区,PHP 输出的各个时区对应的时差表