<!DOCTYPE html>
<html lang="es" dir="ltr">
<head>
<base href="../../../../../">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Servicio SFDatabases.Database</title>
<link rel="shortcut icon" href="media/navigation/favicon.ico">
<link type="text/css" href="normalize.css" rel="Stylesheet">
<link type="text/css" href="prism.css" rel="Stylesheet">
<link type="text/css" href="default.css" rel="Stylesheet">
<script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="languages.js"></script><script type="text/javascript" src="es/langnames.js"></script><script type="text/javascript" src="flexsearch.debug.js"></script><script type="text/javascript" src="prism.js"></script><script type="text/javascript" src="help2.js" defer></script><script type="text/javascript" src="a11y-toggle.js" defer></script><script type="text/javascript" src="paginathing.js" defer></script><script type="text/javascript" src="es/bookmarks.js" defer></script><script type="text/javascript" src="es/contents.js" defer></script><script type="text/javascript" src="help.js" defer></script><meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<header id="TopLeftHeader"><a class="symbol" href="es/text/shared/05/new_help.html"><div></div></a><a class="logo" href="es/text/shared/05/new_help.html"><p dir="auto">Ayuda de LibreOffice 25.2</p></a><div class="dropdowns"><div class="modules">
<button type="button" data-a11y-toggle="modules-nav" id="modules" aria-haspopup="true" aria-expanded="false" aria-controls="modules-nav">Módulo</button><nav id="modules-nav" hidden=""></nav>
</div></div></header><aside class="leftside"><input id="accordion-1" name="accordion-menu" type="checkbox"><label for="accordion-1" dir="auto">Contenido</label><div id="Contents" class="contents-treeview"></div></aside><div id="SearchFrame"><div id="Bookmarks">
<input id="search-bar" type="search" class="search" placeholder="Buscar en los marcadores del módulo elegido" dir="auto"><div class="nav-container" tabindex="0"><nav class="index" dir="auto"></nav></div>
</div></div>
<div id="DisplayArea" itemprop="softwareHelp" itemscope="true" itemtype="http://schema.org/SoftwareApplication">
<noscript><div id="WarnJS"><h1 dir="auto">Active JavaScript en el navegador para mostrar las páginas de ayuda de LibreOffice.</h1></div></noscript>
<a id="ScriptForge-sf_database"></a>
<a id="bm_id151587913266190"></a>
<meta itemprop="keywords" content="Database service">
<a id="abstract"></a>
<h1 id="hd_id371587913266310" dir="auto">
<a id="DatabaseService"></a><span class="literal">SFDatabases</span>.<span class="literal">Database</span> service</h1>
<p id="par_id891599407198144" class="paragraph" dir="auto">The <span class="literal">Database</span> service provides access to databases either embedded or described in Base documents. This service provides methods to:</p>
<ul itemprop="Unordered" itemscope="true" itemtype="http://schema.org/ItemList" dir="auto">
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
<p id="par_id551615386924481" class="listitem" dir="auto">Get access to data in database tables.</p>
</li>
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
<p id="par_id551615386924285" class="listitem" dir="auto">Run <span class="literal">SELECT</span> queries and perform aggregate functions.</p>
</li>
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
<p id="par_id551615386924111" class="listitem" dir="auto">Run SQL action statements such as <span class="literal">INSERT</span>, <span class="literal">UPDATE</span>, <span class="literal">DELETE</span>, etc.</p>
</li>
</ul>
<p id="par_id811599407236602" class="paragraph" dir="auto">Each instance of the <span class="literal">Database</span> service represents a single database and gives access to its tables, queries and data.</p>
<p id="par_id111625692871642" class="paragraph" dir="auto">This service does not provide access to forms or reports in the Base document that contains the database. To access forms in a Base document, refer to the method <a target="_top" href="es/text/sbasic/shared/03/sf_base.html#FormDocuments"><span class="literal">FormDocuments</span></a> of the <span class="literal">Base</span> service.</p>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id231615386789950" dir="auto">All exchanges between this service and the database are done using SQL only.</p></div>
</div>
<br>
<p id="par_id121599407322804" class="paragraph" dir="auto">SQL statements may be run in <span class="emph">direct</span> or <span class="emph">indirect</span> mode. In direct mode the statement is transferred to the database engine without any syntax checking or review.</p>
<p id="par_id681599407189019" class="paragraph" dir="auto">The provided interfaces include simple tables and queries lists, as well as access to database data.</p>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id891599407280007" dir="auto">To make SQL statements more readable, you may use square brackets "[ ]" to enclose names of tables, queries and fields instead of using other enclosing characters that may be exclusive to certain Relational Database Management Systems (RDBMS). But beware that enclosing characters are mandatory in this context.</p></div>
</div>
<br>
<a id="Transaction"></a>
<h2 id="hd_id461701357494930" dir="auto">Transaction handling</h2>
<a id="bm_id121701365380522"></a> <meta itemprop="keywords" content="Database service, Transaction handling">
<p id="par_id71701357507703" class="paragraph" dir="auto">By default the database handles transactions in auto-commit mode, meaning that a commit is done after every SQL statement.</p>
<p id="par_id321701357603871" class="paragraph" dir="auto">Use the <span class="literal">SetTransactionMode</span> method to change the default behavior, which allows for manual commits and rollbacks.</p>
<p id="par_id431701443412927" class="paragraph" dir="auto">The methods <span class="literal">Commit</span> and <span class="literal">Rollback</span> are used to delimit transactions.</p>
<p id="par_id531701365474516" class="paragraph" dir="auto">In LibreOffice, there are five types of transaction isolation modes, as defined in the <a target="_blank" href="https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sdbc_1_1TransactionIsolation.html">com.sun.star.sdbc.TransactionIsolation</a> constant group:</p>
<table border="1" class="" cellpadding="0" cellspacing="0">
<tr>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id631701441607725" class="tableheadintable" dir="auto">Constante</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id671701441607725" class="tableheadintable" dir="auto">Valor</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id441701441607725" class="tableheadintable" dir="auto">Interpretation</p>
</th>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id681701441607725" class="tablecontentintable" dir="auto">NONE</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id831701441607725" class="tablecontentintable" dir="auto">0</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id601701441607725" class="tablecontentintable" dir="auto">Transaction handling is disabled and the database is set to the default auto-commit mode.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id681701441607147" class="tablecontentintable" dir="auto">READ_UNCOMMITTED</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id831701441607208" class="tablecontentintable" dir="auto">1</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id601701441607099" class="tablecontentintable" dir="auto">Dirty reads, non-repeatable reads and phantom reads can occur.</p>
<p id="par_id601701441603205" class="tablecontentintable" dir="auto">If a row is changed by a transaction, another transaction will be able to read these changes even if they have not been committed.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id681701441607317" class="tablecontentintable" dir="auto">READ_COMMITTED</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id831701441607714" class="tablecontentintable" dir="auto">2</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id601701441607012" class="tablecontentintable" dir="auto">Dirty reads are prevented, however non-repeatable reads and phantom reads can occur.</p>
<p id="par_id601701441608244" class="tablecontentintable" dir="auto">This level prevents that rows with uncommitted changes are read.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id681701441607209" class="tablecontentintable" dir="auto">REPEATABLE_READ</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id831701441607103" class="tablecontentintable" dir="auto">4</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id601701441607300" class="tablecontentintable" dir="auto">Dirty reads and non-repeatable reads are prevented. However, phantom reads can occur.</p>
<p id="par_id601701441608161" class="tablecontentintable" dir="auto">Besides preventing uncommitted data from being read, it also prevents that two read operations in the same transaction return different results.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id681701441607060" class="tablecontentintable" dir="auto">SERIALIZABLE</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id831701441607688" class="tablecontentintable" dir="auto">8</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id601701441607896" class="tablecontentintable" dir="auto">Dirty reads, non-repeatable reads and phantom reads are prevented.</p>
<p id="par_id601701441607117" class="tablecontentintable" dir="auto">In addition to the constraints of the previous level, it also ensures that the set of records that match a <span class="literal">WHERE</span> clause remains unchanged inside the same transaction.</p>
</td>
</tr>
</table>
<br>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id991701357744355" dir="auto">Read the Wikipedia page on <a target="_blank" href="https://en.wikipedia.org/wiki/Isolation_(database_systems)">Isolation in Database Systems</a> to learn more about transaction integrity.</p></div>
</div>
<br>
<h2 id="hd_id91587913266988" dir="auto">Invocación del servicio</h2>
<p id="par_id141609955500101" class="paragraph" dir="auto">Antes de utilizar el servicio <span class="literal">Database</span>, es necesario cargar o importar la biblioteca <span class="literal">ScriptForge</span>:</p>
<div class="embedded">
<a id="importLibs"></a>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id901528999850603" dir="auto">• Para cargar la biblioteca <span class="literal">ScriptForge</span> que necesitan las macros de Basic se debe usar la siguiente declaración:<br><span class="literal">GlobalScope.BasicLibraries.loadLibrary("ScriptForge")</span><br><br>• Los scripts de Python necesitan importar el módulo <span class="literal">scriptforge</span>:<br><span class="literal">from scriptforge import CreateScriptService</span></p></div>
</div>
<br>
</div>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id541599408159668" class="paragraph" dir="auto">To create a instance of the <span class="literal">Database</span> service you can use the <span class="literal">CreateScriptService</span> method:</p>
<p id="par_id251625693098616" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">CreateScriptService("SFDatabases.Database", [filename: str], [registrationname], [readonly], [user, [password]]): svc</span>
</p>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id551625693442959" dir="auto">In the syntax described above you can use either "SFDatabases.Database" or simply "Database" as the first argument of the <span class="literal">CreateScriptService</span> method.</p></div>
</div>
<br>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id111615146818256" class="paragraph" dir="auto"><span class="emph">filename</span>: The name of the Base file. Must be expressed using <span class="literal">SF_FileSystem.FileNaming</span> notation.</p>
<p id="par_id771615146944307" class="paragraph" dir="auto"><span class="emph">registrationname</span>: The name of a registered database. If <span class="literal">filename</span> is provided, this argument should not be used.</p>
<p id="par_id491615147048748" class="paragraph" dir="auto">Conversely, if a <span class="literal">registrationname</span> is specified, the <span class="literal">filename</span> parameter should not be defined.</p>
<p id="par_id841615147168279" class="paragraph" dir="auto"><span class="emph">readonly</span>: Determines if the database will be opened as readonly (Default = <span class="literal">True</span>).</p>
<p id="par_id291615147236001" class="paragraph" dir="auto"><span class="emph">user, password</span>: Additional connection parameters to the database server.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
Dim myDatabase as Object
Set myDatabase = CreateScriptService("Database", "/home/user/Documents/myDB.odb")
' Run queries, SQL statements, ...
myDatabase.CloseDatabase()
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
from scriptforge import CreateScriptService
myDatabase = CreateScriptService("Database", "/home/user/Documents/myDB.odb")
# Run queries, SQL statements, ...
myDatabase.CloseDatabase()
</code></pre></div>
<h2 id="hd_id771615147491563" dir="auto">Accessing Databases with the UI Service</h2>
<p id="par_id901599408410712" class="paragraph" dir="auto">It is also possible to access the database associated with a Base document using the <a target="_top" href="es/text/sbasic/shared/03/sf_ui.html"><span class="literal">ScriptForge.UI</span></a> service, as shown in the examples below:</p>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim myDoc As Object, myDatabase As Object, ui As Object
Set ui = CreateScriptService("UI")
Set myDoc = ui.OpenBaseDocument("/home/user/Documents/myDB.odb")
' A continuación se proporcionan el usuario y la contraseña, si hicieran falta
Set myDatabase = myDoc.GetDatabase()
' Run queries, SQL statements, ...
myDatabase.CloseDatabase()
myDoc.CloseDocument()
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
ui = CreateScriptService("UI")
doc = ui.OpenBaseDocument("/home/user/Documents/myDB.odb")
# User and password are supplied below, if needed
myDatabase = doc.GetDatabase()
# Run queries, SQL statements, ...
myDatabase.CloseDatabase()
doc.CloseDocument()
</code></pre></div>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id361619188184750" dir="auto">The <a target="_top" href="es/text/sbasic/shared/03/sf_base.html#GetDatabase">GetDatabase</a> method used in the example above is part of ScriptForge's <span class="literal">Base</span> service.</p></div>
</div>
<br>
<a id="bm_id771615387442357"></a>
<meta itemprop="keywords" content="Database Service,Queries">
<meta itemprop="keywords" content="Database Service,Tables">
<h2 id="hd_id841587913266618" dir="auto">Propiedades</h2>
<a id="properties_toc"></a>
<table border="1" class="" cellpadding="0" cellspacing="0">
<tr>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id521587913266568" class="tableheadintable" dir="auto">Nombre</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id421587913266368" class="tableheadintable" dir="auto">De solo lectura</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id631587914939732" class="tableheadintable" dir="auto">Tipo</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id951587913266220" class="tableheadintable" dir="auto">Descripción</p>
</th>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id161587913266162" class="tablecontentintable" dir="auto">Queries</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id651587913266754" class="tablecontentintable" dir="auto">Sí</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id421587914989890" class="tablecontentintable" dir="auto">Matriz de cadenas</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id351587913266349" class="tablecontentintable" dir="auto">La lista de consultas almacenadas.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id851599409717318" class="tablecontentintable" dir="auto">Tables</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id931599409717463" class="tablecontentintable" dir="auto">Sí</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id71599409717945" class="tablecontentintable" dir="auto">Matriz de cadenas</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id341599409717612" class="tablecontentintable" dir="auto">La lista de tablas almacenadas.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id561599409777730" class="tablecontentintable" dir="auto">XConnection</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id741599409777967" class="tablecontentintable" dir="auto">Sí</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id101599409777906" class="tablecontentintable" dir="auto"><a target="_blank" href="https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1sdbc_1_1XConnection.html">XConnection</a></p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id551599409777759" class="tablecontentintable" dir="auto">El objeto UNO que representa la conexión de base de datos actual.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id361599409887831" class="tablecontentintable" dir="auto">XMetaData</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id271599409887585" class="tablecontentintable" dir="auto">Sí</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id701599409887579" class="tablecontentintable" dir="auto"><a target="_blank" href="https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1sdbc_1_1XDatabaseMetaData.html">XDatabaseMetaData</a></p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id861599409887284" class="tablecontentintable" dir="auto">El objeto UNO que representa los metadatos que describen los atributos del sistema de base de datos.</p>
</td>
</tr>
</table>
<br>
<a id="methods_toc"></a>
<table border="1" class="" cellpadding="0" cellspacing="0">
<tr>
<th rowspan="" colspan="3" class="tableheadcell" dir="auto">
<p id="par_id231614360519973" class="tableheadintable" dir="auto">Lista de métodos en el servicio Database</p>
</th>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id611614360519255" class="tablecontentintable" dir="auto">
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#CloseDatabase">CloseDatabase</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#Commit">Commit</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#CreateDataset">CreateDataset</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#DFunctions">DAvg</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#DFunctions">DCount</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#DFunctions">DMin</a><br>
</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id611614360519104" class="tablecontentintable" dir="auto">
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#DFunctions">DMax</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#DFunctions">DSum</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#DLookup">DLookup</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#GetRows">GetRows</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#OpenFormDocument">OpenFormDocument</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#OpenQuery">OpenQuery</a><br>
</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id611614360518452" class="tablecontentintable" dir="auto">
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#OpenSql">OpenSql</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#OpenTable">OpenTable</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#Rollback">Rollback</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#RunSql">RunSql</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_database.html#SetTransactionMode">SetTransactionMode</a><br><br>
</p>
</td>
</tr>
</table>
<br>
<a id="CloseDatabase"></a>
<a id="bm_id991587913266189"></a>
<meta itemprop="keywords" content="Database Service,CloseDatabase">
<h2 id="hd_id76158791326673" dir="auto">CloseDatabase</h2>
<p id="par_id201587913266596" class="paragraph" dir="auto">Cierra la conexión actual con la base de datos.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id821625699786747" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.CloseDatabase()</span>
</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDatabase.CloseDatabase() ' Basic
</code></pre></div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
myDatabase.CloseDatabase() # Python
</code></pre></div>
<a id="Commit"></a>
<a id="bm_id991587913240529"></a>
<meta itemprop="keywords" content="Database Service,Commit">
<h2 id="hd_id76158791326672" dir="auto">Commit</h2>
<p id="par_id201587913264308" class="paragraph" dir="auto">Commits all updates done since the previous <span class="literal">Commit</span> or <span class="literal">Rollback</span> call.</p>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id391701355293522" dir="auto">This method is ignored if commits are done automatically after each SQL statement, i.e. the database is set to the default auto-commit mode.</p></div>
</div>
<br>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id821625603786747" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.Commit()</span>
</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
' Set the REPEATABLE_READ transaction level
myDB.SetTransactionMode(4)
myDB.RunSql("UPDATE ...")
myDB.Commit()
myDB.RunSql("DELETE ...")
' Test some condition before committing
If bSomeCondition Then
myDB.Commit()
Else
myDB.Rollback()
End If
' Restore auto-commit mode
myDB.SetTransactionMode()
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
myDB.SetTransactionMode(4)
myDB.RunSql("UPDATE ...")
myDB.Commit()
myDB.RunSql("DELETE ...")
if some_condition:
myDB.Commit()
else:
myDB.Rollback()
myDB.SetTransactionMode()
</code></pre></div>
<a id="CreateDataset"></a>
<a id="bm_id161599488115021"></a>
<meta itemprop="keywords" content="Database Service,CreateDataset">
<h2 id="hd_id151599488110425" dir="auto">CreateDataset</h2>
<p id="par_id41599488113502" class="paragraph" dir="auto">Creates a <span class="literal">Dataset</span> service instance based on a table, query or SQL <span class="literal">SELECT</span> statement.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id41625701240781" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.CreateDataset(sqlcommand: str, opt directsql: bool, opt filter: str, opt orderby: str): svc</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id591701267115505" class="paragraph" dir="auto"><span class="emph">sqlcommand</span>: A table name, a query name or a valid SQL <span class="literal">SELECT</span> statement. Identifiers may be enclosed with square brackets. This argument is case-sensitive.</p>
<p id="par_id841701267114060" class="paragraph" dir="auto"><span class="emph">directsql</span>: Set this argument to <span class="literal">True</span> to send the statement directly to the database engine without preprocessing by LibreOffice (Default = <span class="literal">False</span>).</p>
<p id="par_id241701267114527" class="paragraph" dir="auto"><span class="emph">filter</span>: Specifies the condition that records must match to be included in the returned dataset. This argument is expressed as a SQL <span class="literal">WHERE</span> statement without the "WHERE" keyword.</p>
<p id="par_id471701267115093" class="paragraph" dir="auto"><span class="emph">orderby</span>: Specifies the ordering of the dataset as a SQL <span class="literal">ORDER BY</span> statement without the "ORDER BY" keyword.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<p id="par_id941701267748877" class="paragraph" dir="auto">Los ejemplos siguientes en BASIC y Python devuelven un conjunto de datos con los registros de una tabla denominada «Clientes».</p>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
oDataset = myDatabase.CreateDataset("Clientes", Filter := "[Name] LIKE 'A'")
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
dataset = myDatabase.CreateDataset("Customers", Filter = "[Name] LIKE 'A'")
</code></pre></div>
<a id="DFunctions"></a>
<a id="bm_id861599488343584"></a>
<meta itemprop="keywords" content="Database Service,DAvg">
<a id="bm_id221599488343636"></a>
<meta itemprop="keywords" content="Database Service,DCount">
<a id="bm_id261599488343619"></a>
<meta itemprop="keywords" content="Database Service,DMax">
<a id="bm_id231599488343876"></a>
<meta itemprop="keywords" content="Database Service,DMin">
<a id="bm_id831599488343138"></a>
<meta itemprop="keywords" content="Database Service,DSum">
<h2 id="hd_id281596554849363" dir="auto">DAvg, DCount, DMin, DMax, DSum</h2>
<p id="par_id13159655484952" class="paragraph" dir="auto">Calcula la función de totalización en un campo o una expresión perteneciente a una tabla.</p>
<p id="par_id101615148468548" class="paragraph" dir="auto">Optionally, a SQL <span class="literal">WHERE</span> clause can be specified as a filter that will be applied prior to the aggregate function.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id481625700732942" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.DAvg(expression: str, tablename: str, [criteria: str]): any</span>
</p>
<p id="par_id481625700732113" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.DCount(expression: str, tablename: str, [criteria: str]): any</span>
</p>
<p id="par_id481625700730298" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.DMin(expression: str, tablename: str, [criteria: str]): any</span>
</p>
<p id="par_id481625700720177" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.DMax(expression: str, tablename: str, [criteria: str]): any</span>
</p>
<p id="par_id481625700731179" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.DSum(expression: str, tablename: str, [criteria: str]): any</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id441596554849949" class="paragraph" dir="auto"><span class="emph">expression</span>: A SQL expression in which the field names are surrounded with square brackets.</p>
<p id="par_id381596554849698" class="paragraph" dir="auto"><span class="emph">tablename</span>: A table name (without square brackets).</p>
<p id="par_id521596554849185" class="paragraph" dir="auto"><span class="emph">criteria</span>: A <span class="literal">WHERE</span> clause without the "WHERE" keyword, in which field names are surrounded with square brackets.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<p id="par_id781615150306678" class="paragraph" dir="auto">The example below assumes the file <span class="literal">Employees.odb</span> has a table named <span class="literal">EmployeeData</span>.</p>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
Dim myDB as Variant
Set myDB = CreateScriptService("Database", "/home/user/Databases/Employees.odb")
' Cuenta todos los empleados en la tabla
MsgBox myDB.DCount("[ID]", "EmployeeData")
' Devuelve la suma de todos los salarios en la tabla
MsgBox myDB.DSum("[Salary]", "EmployeeData")
' Below are some examples of how tables can be filtered
MsgBox myDB.DCount("[ID]", "EmployeeData", "[Position] = 'Manager'")
MsgBox myDB.DCount("[ID]", "EmployeeData", "[Position] = 'Sales' AND [City] = 'Chicago'")
MsgBox myDB.DCount("[ID]", "EmployeeData", "[FirstName] LIKE 'Paul%'")
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
myDB = CreateScriptService("Database", "/home/user/Databases/Employees.odb")
bas = CreateScriptService("Basic")
bas.MsgBox(myDB.DCount("[ID]", "EmployeeData"))
bas.MsgBox(myDB.DSum("[Salary]", "EmployeeData"))
bas.MsgBox(myDB.DCount("[ID]", "EmployeeData", "[Position] = 'Manager'"))
bas.MsgBox(myDB.DCount("[ID]", "EmployeeData", "[Position] = 'Sales' AND [City] = 'Chicago'"))
bas.MsgBox(myDB.DCount("[ID]", "EmployeeData", "[FirstName] LIKE 'Paul%'"))
</code></pre></div>
<a id="DLookup"></a>
<a id="bm_id161599488113736"></a>
<meta itemprop="keywords" content="Database Service,DLookup">
<h2 id="hd_id151599488113565" dir="auto">DLookup</h2>
<p id="par_id41599488113961" class="paragraph" dir="auto">Computes a SQL expression on a single record returned by a <span class="literal">WHERE</span> clause defined by the <span class="literal">Criteria</span> parameter.</p>
<p id="par_id601615381471954" class="paragraph" dir="auto">If the query returns multiple records, only the first one is considered. Use the <span class="literal">OrderClause</span> parameter to determine how query results are sorted.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id41625701240138" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.DLookup(expression: str, tablename: str, [criteria:str], [orderclause: str]): any</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id671599488113986" class="paragraph" dir="auto"><span class="emph">expression</span>: A SQL expression in which the field names are surrounded with square brackets.</p>
<p id="par_id441599488113247" class="paragraph" dir="auto"><span class="emph">tablename</span>: A table name (without square brackets).</p>
<p id="par_id40159948811316" class="paragraph" dir="auto"><span class="emph">criteria</span>: A <span class="literal">WHERE</span> clause without the "WHERE" keyword, in which field names are surrounded with square brackets.</p>
<p id="par_id71599488689029" class="paragraph" dir="auto"><span class="emph">orderclause</span>: An <span class="literal">ORDER BY</span> clause without the "ORDER BY" keywords. Field names should be surrounded with square brackets.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
MsgBox myDB.DLookup("[FirstName]", "EmployeeData", Criteria := "[LastName] LIKE 'Smith'", OrderClause := "[FirstName] DESC")
MsgBox myDB.DLookup("[Salary]", "EmployeeData", Criteria := "[ID] = '3'")
MsgBox myDB.DLookup("[Quantity] * [Value]", "Sales", Criteria := "[SaleID] = '5014'")
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
bas = CreateScriptService("Basic")
bas.MsgBox(myDB.DLookup("[FirstName]", "EmployeeData", criteria = "[LastName] LIKE 'Smith'", orderclause = "[FirstName] DESC"))
bas.MsgBox(myDB.DLookup("[Salary]", "EmployeeData", criteria = "[ID] = '3'"))
bas.MsgBox(myDB.DLookup("[Quantity] * [Value]", "Sales", criteria = "[SaleID] = '5014'"))
</code></pre></div>
<a id="GetRows"></a>
<a id="bm_id91599489278645"></a>
<meta itemprop="keywords" content="Database Service,GetRows">
<h2 id="hd_id79159948927847" dir="auto">GetRows</h2>
<p id="par_id481599489278579" class="paragraph" dir="auto">Stores the contents of a table or the results of a <span class="literal">SELECT</span> query or of an SQL statement in a two-dimensional array. The first index in the array corresponds to the rows and the second index refers to the columns.</p>
<p id="par_id821615384762425" class="paragraph" dir="auto">An upper limit can be specified to the number of returned rows. Optionally column names may be inserted in the first row of the array.</p>
<p id="par_id271599490209915" class="paragraph" dir="auto">The returned array will be empty if no rows are returned and the column headers are not required.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id121625701537873" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.GetRows(sqlcommand: str, directsql: bool = False, header: bool = False, maxrows: int = 0): any</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id451599489278429" class="paragraph" dir="auto"><span class="emph">sqlcommand</span>: A table or query name (without square brackets) or a <span class="literal">SELECT</span> SQL statement.</p>
<p id="par_id271599489278141" class="paragraph" dir="auto"><span class="emph">directsql</span>: When <span class="literal">True</span>, the SQL command is sent to the database engine without pre-analysis. Default is <span class="literal">False</span>. This argument is ignored for tables. For queries, the applied option is the one set when the query was defined.</p>
<p id="par_id941599489278747" class="paragraph" dir="auto"><span class="emph">header</span>: When <span class="literal">True</span>, the first row of the returned array contains the column headers.</p>
<p id="par_id591599489278926" class="paragraph" dir="auto"><span class="emph">maxrows</span>: The maximum number of rows to return. The default is zero, meaning there is no limit to the number of returned rows.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<p id="par_id721615385125947" class="paragraph" dir="auto">A continuación se proporcionan algunos ejemplos de uso del método <span class="literal">GetRows</span>:</p>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim queryResults as Variant
' Returns all rows in the table with column headers
queryResults = myDB.GetRows("EmployeeData", Header := True)
' Returns the first 50 employee records ordered by the 'FirstName' field
queryResults = myDB.GetRows("SELECT * FROM EmployeeData ORDER BY [FirstName]", MaxRows := 50)
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
queryResults = myDB.GetRows("EmployeeData", header = True)
queryResults = myDB.GetRows("SELECT * FROM EmployeeData ORDER BY [FirstName]", maxrows = 50)
</code></pre></div>
<a id="OpenFormDocument"></a>
<a id="bm_id341619035528912"></a>
<meta itemprop="keywords" content="Database service,OpenFormDocument">
<h2 id="hd_id611619035632927" dir="auto">OpenFormDocument</h2>
<p id="par_id801619099743199" class="paragraph" dir="auto">Opens the specified form document in normal mode. This method returns a <span class="literal">FormDocument</span> service instance corresponding to the specified form document.</p>
<p id="par_id451619100075330" class="paragraph" dir="auto">If the form document is already open, the form document window is activated.</p>
<p id="par_id651692554712005" class="paragraph" dir="auto">If the specified form document does not exist, then <span class="literal">Nothing</span> is returned.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id71623105516650" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">svc.OpenFormDocument(formdocument: str): svc</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id941619099797810" class="paragraph" dir="auto"><span class="emph">formdocument:</span> The name of the <span class="literal">FormDocument</span> to be opened, as a case-sensitive string.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<p id="par_id251619100191992" class="paragraph" dir="auto">La mayor parte de los formularios se almacenan en la raíz del documento de Base y pueden abrirse simplemente utilizando sus nombres, como en el ejemplo siguiente:</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim oFormDoc As Object
oFormDoc = myDB.OpenFormDocument("myFormDocument")
</code></pre></div>
<p id="par_id351619100327505" class="paragraph" dir="auto">Si los documentos de formulario se organizan en carpetas, se vuelve necesario incluir el nombre de la carpeta para especificar el documento que se debe abrir, como se ilustra en el ejemplo siguiente:</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
oFormDoc = myDB.OpenFormDocument("myFolder/myFormDocument")
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
formDoc = myDB.OpenFormDocument("myFormDocument")
</code></pre></div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
formDoc = myDB.OpenFormDocument("myFolder/myFormDocument")
</code></pre></div>
<a id="OpenQuery"></a>
<a id="bm_id781599490609222"></a>
<meta itemprop="keywords" content="Database Service,OpenQuery">
<h2 id="hd_id80159949060014" dir="auto">OpenQuery</h2>
<p id="par_id31599490604484" class="paragraph" dir="auto">Opens the Data View window of the specified query and returns an instance of the <span class="literal">Datasheet</span> service.</p>
<p id="par_id801671111609985" class="paragraph" dir="auto">If the query could not be opened, then <span class="literal">Nothing</span> is returned.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id421625701780171" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.OpenQuery(queryname: str): obj</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id701599490609511" class="paragraph" dir="auto"><span class="emph">queryname</span>: The name of an existing query as a case-sensitive String.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDatabase.OpenQuery("MyQuery")
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
myDatabase.OpenQuery("MyQuery")
</code></pre></div>
<a id="OpenSql"></a>
<a id="bm_id781599490609302"></a>
<meta itemprop="keywords" content="Database Service,OpenSql">
<h2 id="hd_id80159949060989" dir="auto">OpenSql</h2>
<p id="par_id31599490601045" class="paragraph" dir="auto">Runs a SQL <span class="literal">SELECT</span> command, opens a Data View window with the results and returns an instance of the <span class="literal">Datasheet</span> service.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id421625701780011" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.OpenSql(sql: str, directsql: bool): obj</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id701599490604461" class="paragraph" dir="auto"><span class="emph">sql</span>: A string containing a valid SQL SELECT statement. Identifiers may be enclosed by square brackets.</p>
<p id="par_id51599490609622" class="paragraph" dir="auto"><span class="emph">directsql</span>: When <span class="literal">True</span>, the SQL command is sent to the database engine without pre-analysis (Default = <span class="literal">False</span>).</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDatabase.OpenSql("SELECT * FROM [Customers] ORDER BY [CITY]")
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
myDatabase.OpenSql("SELECT * FROM [Customers] ORDER BY [CITY]")
</code></pre></div>
<a id="OpenTable"></a>
<a id="bm_id781599490609404"></a>
<meta itemprop="keywords" content="Database Service,OpenTable">
<h2 id="hd_id80159949063914" dir="auto">OpenTable</h2>
<p id="par_id31599490605021" class="paragraph" dir="auto">Opens the Data View window of the specified table and returns an instance of the <span class="literal">Datasheet</span> service.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id421625701750551" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.OpenTable(tablename: str): obj</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id701599490609021" class="paragraph" dir="auto"><span class="emph">tablename</span>: The name of an existing table as a case-sensitive String.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDatabase.OpenTable("MyTable")
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
myDatabase.OpenTable("MyTable")
</code></pre></div>
<a id="Rollback"></a>
<a id="bm_id781599490603364"></a>
<meta itemprop="keywords" content="Database Service,Rollback">
<h2 id="hd_id80159949010214" dir="auto">Rollback</h2>
<p id="par_id31599490603311" class="paragraph" dir="auto">Cancels all changes made to the database since the last <span class="literal">Commit</span> or <span class="literal">Rollback</span> call.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id421625701753721" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.Rollback()</span>
</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDB.SetTransactionMode(1)
myDB.RunSql("UPDATE ...")
' ...
If bSomeCondition Then
myDB.Rollback()
End If
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
myDB.SetTransactionMode(1)
myDB.RunSql("UPDATE ...")
# ...
if bSomeCondition:
myDB.Rollback()
</code></pre></div>
<a id="RunSql"></a>
<a id="bm_id781599490609499"></a>
<meta itemprop="keywords" content="Database Service,RunSql">
<h2 id="hd_id80159949060917" dir="auto">RunSql</h2>
<p id="par_id31599490609759" class="paragraph" dir="auto">Executes an action query of an SQL statement such as creating a table, as well as inserting, updating and deleting records.</p>
<p id="par_id331615385491925" class="paragraph" dir="auto">The method returns <span class="literal">True</span> when successful.</p>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id21599490810021" dir="auto">The <span class="literal">RunSql</span> method is rejected with an error message in case the database was previously opened in read-only mode.</p></div>
</div>
<br>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id421625701780046" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.RunSql(sqlcommand: str, directsql: bool = False): bool</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id701599490609473" class="paragraph" dir="auto"><span class="emph">sqlcommand</span>: A query name (without square brackets) or a SQL statement.</p>
<p id="par_id51599490609377" class="paragraph" dir="auto"><span class="emph">directsql</span>: When <span class="literal">True</span>, the SQL command is sent to the database engine without pre-analysis. (Default = <span class="literal">False</span>). For queries, the applied option is the one set when the query was defined.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDatabase.RunSql("INSERT INTO [EmployeeData] VALUES(25, 'Smith', 'John')", DirectSQL := True)
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
myDatabase.RunSql("INSERT INTO [EmployeeData] VALUES(25, 'Smith', 'John')", directsql = True)
</code></pre></div>
<a id="SetTransactionMode"></a>
<a id="bm_id781599490603230"></a>
<meta itemprop="keywords" content="Database Service,SetTransactionMode">
<h2 id="hd_id80159949010722" dir="auto">SetTransactionMode</h2>
<p id="par_id31599490604648" class="paragraph" dir="auto">Defines the level of isolation in database transactions.</p>
<p id="par_id281701459963822" class="paragraph" dir="auto">By default databases manage transactions in auto-commit mode, which means that a <span class="literal">Commit</span> is automatically performed after every SQL statement.</p>
<p id="par_id181701460140309" class="paragraph" dir="auto">Use this method to manually determine the isolation level of transactions. When a transaction mode other than <span class="literal">NONE</span> is set, the script has to explicitly call the <span class="literal">Commit</span> method to apply the changes to the database.</p>
<p id="par_id211701461020712" class="paragraph" dir="auto">This method returns <span class="literal">True</span> when successful.</p>
<div class="warning">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/warning.svg" alt="warning" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id831701530239962" dir="auto">Changing the transaction mode closes all <span class="literal">Dataset</span> instances created from the current database.</p></div>
</div>
<br>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id421625701752132" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">db.SetTransactionMode(transactionmode: int = 0): bool</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id701599490609584" class="paragraph" dir="auto"><span class="emph">transactionmode</span>: Specifies the transaction mode. This argument must be one of the constants defined in <a target="_blank" href="https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sdbc_1_1TransactionIsolation.html">com.sun.star.sdbc.TransactionIsolation</a> (Default = <span class="literal">NONE</span>)</p>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id301701459879269" dir="auto">Read the section <a target="_top" href="es/text/sbasic/shared/03/sf_database.html#Transaction">Transaction handling</a> above to learn more about the transaction isolation levels used in LibreOffice.</p></div>
</div>
<br>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDB.SetTransactionMode(com.sun.star.sdbc.TransactionIsolation.REPEATABLE_READ)
oDataset = myDB.CreateDataset("SELECT ...")
' ...
' Reset the transaction mode to default
myDB.SetTransactionMode()
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
from com.sun.star.sdbc import TransactionIsolation
myDB.SetTransactionMode(TransactionIsolation.REPEATABLE_READ)
dataset = myDB.CreateDataset("SELECT ...")
# ...
myDB.SetTransactionMode()
</code></pre></div>
<div class="embedded">
<a id="SF_InternalUse"></a>
<div class="warning">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/warning.svg" alt="warning" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id851506659675843" dir="auto">Todas las rutinas o identificadores BASIC de <span class="literal">ScriptForge</span> precedidas por guion bajo «_» están reservadas para uso interno. No deben utilizarse en macros BASIC o secuencias Python.</p></div>
</div>
<br>
</div>
<a id="relatedtopics"></a><div class="relatedtopics">
<p class="related" itemprop="mentions" dir="auto"><a id="related"></a><span class="emph">Temas relacionados</span></p>
<div class="relatedbody" itemprop="mentions">
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="es/text/sbasic/shared/03/sf_datasheet.html">Servicio <span class="literal">SFDatabases</span>.<span class="literal">Datasheet</span></a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="es/text/sbasic/shared/03/sf_dataset.html">Servicio <span class="literal">SFDatabases</span>.<span class="literal">Dataset</span></a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="es/text/sbasic/shared/03/sf_document.html">Servicio <span class="literal">SFDocuments</span>.<span class="literal">Document</span></a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="es/text/sbasic/shared/03/sf_form.html"><span class="literal">SFDocuments</span>.<span class="literal">Form</span> service</a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="es/text/sbasic/shared/03/sf_ui.html">Servicio <span class="literal">ScriptForge</span>.<span class="literal">UI</span></a></p></div>
</div>
</div>
</div>
<div id="DonationFrame"></div>
<footer><h2 style="text-align: center;"><a href="https://books.libreoffice.org" target="_blank">Libros de LibreOffice</a></h2>
<div class="noteicon" dir="auto" style="display:flex;justify-content:center;flex-wrap:wrap;row-gap:15px;">
<img src="media/navigation/libo-writer.svg" alt="Writer Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-calc.svg" alt="Calc Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-impress.svg" alt="Impress Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-draw.svg" alt="Draw Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-base.svg" alt="Base Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-math.svg" alt="Math Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-symbol-black.svg" alt="Getting Started Icon" style="width:60px;height:60px;">
</div>
<div id="DEBUG" class="debug">
<h3 class="bug">Help content debug info:</h3>
<p dir="auto">This page is: <a href="https://opengrok.libreoffice.org/xref/help/source/text/sbasic/shared/03/sf_database.xhp" target="_blank">/text/sbasic/shared/03/sf_database.xhp</a></p>
<p dir="auto">Title is: Servicio SFDatabases.Database</p>
<p id="bm_module" dir="auto"></p>
<p id="bm_system" dir="auto"></p>
<p id="bm_HID" dir="auto"></p>
</div></footer>
</body>
</html>