<doc>
  <legacy_id>1662</legacy_id>
  <name>revQueryDatabase</name>
  <type>function</type>
  <syntax>
    <example>revQueryDatabase(<i>databaseID</i>,<i>SQLQuery</i>[,{<i>variablesList</i> | <i>arrayName</i>}])</example>
  </syntax>
  <library>Database library</library>
  <objects>
  </objects>
  <synonyms>
    <synonym>revdb_query</synonym>
    <synonym>revQueryDatabaseBlob</synonym>
  </synonyms>
  <classification>
    <category>Database Operations</category>
    <category>Standalone Applications</category>
  </classification>
  <references>
    <command tag="revCloseCursor">revCloseCursor Command</command>
    <command tag="revExecuteSQL">revExecuteSQL Command</command>
    <function tag="revQueryIsAtStart">revQueryIsAtStart Function</function>
  </references>
  <history>
    <introduced version="1.1">Added.</introduced>
    <changed version="2.0"></changed>
  </history>
  <platforms>
    <mac/>
    <windows/>
    <linux/>
    <ios/>
    <android/>
  </platforms>
  <classes>
    <desktop/>
    <server/>
    <web/>
    <mobile/>
  </classes>
  <security>
    <disk access="???"/>
    <network/>
  </security>
  <summary>Selects <glossary tag="record">records</glossary> in a <glossary tag="database">database</glossary> according to a <glossary tag="SQL query">SQL query</glossary>.</summary>
  <examples>
    <example>revQueryDatabase(2,"SELECT * FROM EmpStats")</example>
    <example>revQueryDatabase(currentDB,field "Query")</example>
    <example>revQueryDatabase(the database of me,myQuery,"myVar1","myVar2","myVar3")</example>
    <example>revQueryDatabase(tConnectionId, tQuery, "tInputData[id]", "tInputData[name]")</example>
  </examples>
  <description>
    <p>Use the <b>revQueryDatabase</b> <control_st tag="function">function</control_st> to select <glossary tag="record">records</glossary> in a <glossary tag="database">database</glossary> to work on.</p><p/><p><b>Parameters:</b></p><p>The <i>databaseID</i> is the number <glossary tag="return">returned</glossary> by the <function tag="revOpenDatabase">revOpenDatabase</function> <control_st tag="function">function</control_st> when the <glossary tag="database">database</glossary> was opened.</p><p/><p>The <i>SQLQuery</i> is a <keyword tag="string">string</keyword> in <glossary tag="SQL">Structured Query Language</glossary> that contains a SELECT statement. (Do not include a semicolon at the end of the <i>SQLQuery</i>.)</p><p/><p>The <i>variablesList</i> consists of one or more <glossary tag="variable">variable</glossary> names (or expressions that evaluate to <glossary tag="variable">variable</glossary> names), separated by commas. As of version 2.9, each variable name can also be the name of an array element, for example "tInputData[myKey]".</p><p/><p>The <i>arrayName</i> is the name of a single <glossary tag="array">array</glossary> <glossary tag="variable">variable</glossary> whose <function tag="keys">keys</function> are sequential numbers.</p><p/><p><b>Note:</b> The <glossary tag="variable">variable</glossary> names or <i>arrayName</i> must be enclosed in quotes; otherwise, the variable's value rather than its name is passed to the <b>revQueryDatabase</b> <control_st tag="function">function</control_st>.</p><p/><p><b>Value:</b></p><p>The <b>revQueryDatabase</b> <control_st tag="function">function</control_st> returns a record set ID which designates the <glossary tag="record set (database cursor)">record set (database cursor)</glossary> selected by the <i>SQLQuery</i>. The record set ID is an <keyword tag="integer">integer</keyword>.</p><p/><p><b>Comments:</b></p><p>The <i>SQLQuery</i> may contain one or more placeholders, which are sequential numbers <glossary tag="prepend">prepended</glossary> by a colon. The <b>revQueryDatabase</b> <control_st tag="function">function</control_st> substitutes the corresponding variable name in the <i>variablesList</i> for each of these placeholders. For example, if you have two <glossary tag="variable">variables</glossary> called "valueX" and "valueY", you can use a <i>SQLQuery</i> that includes placeholders as follows:</p><p/><p>  get revQueryDatabase(myID,"SELECT * FROM empStats WHERE id=:1 OR stat_id=:1 OR population=:2","valueX","valueY")</p><p/><p>The content of the variable valueX is substituted for the ":1" in the <i>SQLQuery</i> (in both places where ":1" appears), and the content of valueY is substituted for ":2".</p><p/><p>If you specify an <i>arrayName</i> rather than a list of ordinary <glossary tag="variable">variables</glossary>, the <b>revQueryDatabase</b> function substitutes the corresponding <keyword tag="element">element</keyword> of the <glossary tag="array">array</glossary> for each of the placeholders in the <glossary tag="SQL query">query</glossary>:</p><p/><p>  get revQueryDatabase(myID,"SELECT :1,:2 FROM empStats WHERE 1",myArray)</p><p/><p>The content of the element myArray[1] is substituted for the ":1" in the <i>SQLQuery</i> (in both places where ":1" appears), and the content of myArray[2] is substituted for ":2".</p><p/><p>To pass binary data in a variable in the <i>variablesList</i>, <glossary tag="prepend">prepend</glossary> "*b" to the variable name. The <b>revQueryDatabase</b> <control_st tag="function">function</control_st> strips the binary marker "*b" and passes it to the database as binary data, rather than text data. To pass <glossary tag="binary data">binary data</glossary> in an <glossary tag="array">array</glossary> <keyword tag="element">element</keyword>, prepend "*b" to the <glossary tag="element">element's</glossary> value.</p><p/><p><img src="202651"/> <b>Tip:</b> To execute a <glossary tag="SQL query">SQL query</glossary> that does not return a <glossary tag="record set (database cursor)">record set (database cursor)</glossary> (such as INSERT or DELETE), use the <command tag="revExecuteSQL">revExecuteSQLcommand</command> instead. Since <command tag="revExecuteSQL">revExecuteSQL</command> does not allocate storage for returned data, it is more efficient than <b>revQueryDatabase</b> for <glossary tag="SQL query">SQL queries</glossary> where no data is returned.</p><p/><p>If the query is not successful, the <b>revQueryDatabase</b> <control_st tag="function">function</control_st> returns an error message.  The error message is never an <keyword tag="integer">integer</keyword>, so you can check whether the query was successful by checking whether the <glossary tag="return value">return value</glossary> is an <keyword tag="integer">integer</keyword> or not.</p><p/><p><img src="202653"/> <b>Important!</b> The <b>revQueryDatabase</b> <control_st tag="function">function</control_st> is part of the <glossary tag="Database library">Database library</glossary>. To ensure that the <control_st tag="function">function</control_st> works in a <glossary tag="standalone application">standalone application</glossary>, you must include this <glossary tag="LiveCode custom library">custom library</glossary> when you create your <glossary tag="standalone application">standalone</glossary>. In the Inclusions section of the General screen of the <glossary tag="Standalone Application Settings">Standalone Application Settings</glossary> window, make sure the "Database Support" checkbox is checked and the database drivers you are using are selected in the list of database drivers.</p><p/><p><b>Changes:</b></p><p>The <b>revQueryDatabase</b> synonym was added in version 2.0.</p>
  </description>
</doc>