Documentation update - example simplification

This commit is contained in:
carregal 2005-08-05 22:49:42 +00:00
parent 6378588b72
commit 23dfaf3d34
2 changed files with 14 additions and 12 deletions

View File

@ -118,8 +118,7 @@ Nome: Maria das Dores, E-mail: maria@dores.com
<pre class="example">
function rows (connection, sql_statement)
local cursor, err = connection:execute (sql_statement)
assert (cursor, string.format ("%s (%s)", err, sql_statement))
local cursor = assert (connection:execute (sql_statement))
return function ()
return cursor:fetch()
end
@ -133,10 +132,16 @@ require"luasql.mysql"
env = assert (luasql.mysql())
con = assert (env:connect"my_db")
for id, name, address in rows (con, "select * from contacts") do
print ("%s: %s", name, address)
print (string.format ("%s: %s", name, address))
end
</pre>
<p>A implementa&ccedil;&atilde;o acima utiliza a coleta de lixo de Lua para
fechar o cursor. Ela pode ser melhorada de modo a apresentar
mensagens de erro mais adequadas (incluindo o statement SQL por
exemplo) ou para fechar explicitamente o cursor (verificando
se ainda existem mais linhas por exemplo).</p>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
@ -144,7 +149,7 @@ end
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
<p><small>
$Id: examples.html,v 1.3 2005/05/22 18:51:25 carregal Exp $
$Id: examples.html,v 1.4 2005/08/05 22:49:42 carregal Exp $
</small></p>
</div> <!-- id="about" -->

View File

@ -136,14 +136,11 @@ for id, name, address in rows (con, "select * from contacts") do
end
</pre>
<p>
The iterator could be improved to give better error messages
<p>The above implementation relies on the garbage collector to close
the cursor. It could be improved to give better error messages
(including the SQL statement, for example)
and also explicit close the cursor
(by checking whether there are no more rows).
The above implementation will rely on the garbage collector to close
the cursor.
</p>
or to explicit close the cursor
(by checking whether there are no more rows).</p>
</div> <!-- id="content" -->
@ -152,7 +149,7 @@ the cursor.
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
<p><small>
$Id: examples.html,v 1.10 2005/08/05 12:45:21 tomas Exp $
$Id: examples.html,v 1.11 2005/08/05 22:49:42 carregal Exp $
</small></p>
</div> <!-- id="about" -->