<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GustavoHenrique.net &#187; firebird</title>
	<atom:link href="http://blog.gustavohenrique.net/tag/firebird/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gustavohenrique.net</link>
	<description>Tecnologia e Software Livre</description>
	<lastBuildDate>Wed, 25 Jan 2012 10:34:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Acessando BD Firebird através do KinterbasDB no Python</title>
		<link>http://blog.gustavohenrique.net/2010/01/acessando-firebird-atraves-do-kinterbasdb-no-python/</link>
		<comments>http://blog.gustavohenrique.net/2010/01/acessando-firebird-atraves-do-kinterbasdb-no-python/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 15:00:12 +0000</pubDate>
		<dc:creator>gustavohenrique</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[firebird]]></category>

		<guid isPermaLink="false">http://www.gustavohenrique.net/brogui/?p=226</guid>
		<description><![CDATA[KinterbasDB é uma biblioteca open source para Python que possibilita acessar banco de dados Firebird e algumas versões do Interbase. O download pode ser feito na página do projeto. Após o download, descompacte o pacote kinterbasdb-3.2.src.tar.gz. Abra um terminal, entre no diretório onde o kinterbasdb foi descompactado e execute o comando python setup.py build. O [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.gustavohenrique.net/wp-content/uploads/2010/01/firebird-icon.gif"><img src="http://blog.gustavohenrique.net/wp-content/uploads/2010/01/firebird-icon.gif" alt="firebird-icon" title="firebird-icon" width="66" height="67" class="aligncenter size-full wp-image-229" /></a></p>
<p>KinterbasDB é uma biblioteca open source para Python que possibilita acessar banco de dados Firebird e algumas versões do Interbase.<br />
O download pode ser feito na <a href="http://kinterbasdb.sourceforge.net/" target="_blank">página do projeto</a>.</p>
<p>Após o download, descompacte o pacote <code>kinterbasdb-3.2.src.tar.gz</code>.<br />
Abra um terminal, entre no diretório onde o kinterbasdb foi descompactado e execute o comando <code>python setup.py build</code>. O script de instalação, setup.py, automaticamente vai detectar as informações necessárias pelo compilador C.<br />
Se não ocorreu nenhum erro, execute o comando <code>python setup.py install</code> para instalar no diretório padrão de módulos do Python (varia de acordo com a distro).</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">root@localhost: ~# wget http://downloads.sourceforge.net/project/kinterbasdb/kinterbasdb/kinterbasdb-3.2/kinterbasdb-3.2.src.tar.gz?use_mirror=ufpr
root@localhost: ~# tar zxvf kinterbasdb-3.2.src.tar.gz
root@localhost: ~# python setup.py build
Succeeded:
  /usr/bin/python setup.py build
root@localhost: ~# python setup.py install</pre></div></div>

<p>Para testar se foi instalado corretamente:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">root@localhost: ~# python -c &quot;import kinterbasdb as k; print k.__version__&quot;
(3, 2, 0, 'final', 0)
root@localhost: ~#</pre></div></div>

<p>É possível que apareça uma mensagem de erro em distros baseadas no Ubuntu:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
kinterbasdb.OperationalError: (-901, 'begin transaction: \n  invalid parameter in transaction parameter block')</pre></div></div>

<p>Para corrigir esse problema é preciso usar uma outra versão do arquivo <code>__init__.py</code>.<br />
Faça o download em <a href="https://firebird.svn.sourceforge.net/svnroot/firebird/qa/trunk/kinterbasdb/__init__.py" target="_blank">https://firebird.svn.sourceforge.net/svnroot/firebird/qa/trunk/kinterbasdb/__init__.py</a> e substitua o arquivo existente no diretório <code>kinterbasdb</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">root@localhost: ~# wget https://firebird.svn.sourceforge.net/svnroot/firebird/qa/trunk/kinterbasdb/__init__.py
root@localhost: ~# mv __init__.py /usr/lib/python2.5/site-packages/kinterbasdb/</pre></div></div>

<p>Exemplo para Firebird-2.1 em servidor Windows:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> kinterbasdb
conn = kinterbasdb.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>
    host=<span style="color: #483d8b;">'192.168.0.2'</span>,
    database=<span style="color: #483d8b;">'C:<span style="color: #000099; font-weight: bold;">\\</span>Dados<span style="color: #000099; font-weight: bold;">\\</span>meubanco.fdb'</span>,
    <span style="color: #dc143c;">user</span>=<span style="color: #483d8b;">'sysdba'</span>,
    password=<span style="color: #483d8b;">'masterkey'</span>
<span style="color: black;">&#41;</span>
cur = conn.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
cur.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'SELECT id, nome, telefone FROM tabela'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span><span style="color: #008000;">id</span>, nome, telefone<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> cur:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'ID: %s, Nome: %s, Fone: %s'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #008000;">id</span>, nome, telefone<span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.gustavohenrique.net/2010/01/acessando-firebird-atraves-do-kinterbasdb-no-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

