📄 executingqueries.htm
字号:
<html>
<head>
<title>Executing Queries</title>
</head>
<!--#include virtual="/inc/header.php"-->
<table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#FFFFFF">
<tr>
<td align="left">
<span style="font-family:Helvetica,Arial; font-size:12pt; color:#000000"><b>Executing Queries
<br>
</b></span>
</td>
<td align="right">
<font face="Arial" size="2">
<a href="openingtables.htm">Previous</a>
<a href="overview.htm">Top</a>
<a href="usingparametersinqueries.htm">Next</a>
</font>
</td>
</tr>
</table>
<br><br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b>Executing a query</b></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">
<br>
</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
Use Absolute Database DBManager utility (...\AbsoluteDatabase\Ultils\Bin\DBManager.exe), if you would like to execute SQL query manually.
<br>
<br>
To execute an SQL query from your application, you can perform the following steps:
<br>
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">1.</span></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>Place </b><b><a href=tabsdatabase.htm>TABSDatabase</a></b><b> and </b><b><a href=tabsquery.htm>TABSQuery</a></b><b> components</b> <span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">from the Absolute DB page of the Component palette to a data module or on a form, if you have not already done it.</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">2.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>Set up TABSDatabase component</b>. <span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">Set the </span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">TABSDatabase.<span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabsdatabase_databasename.htm>DatabaseName</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> of the component to a unique value that will be used later to identify the database. Set the </span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">TABSDatabase.<span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabsdatabase_databasefilename.htm>DatabaseFileName</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> property to the name of the existing or new database file, if you have not already done it.
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">3.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>Set up TABSQuery component. </b>Set the <span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">TABSQuery.</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabsdataset_databasename.htm>DatabaseName</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> property from the drop-down list of available TABSDatabase components. Assign the query command(s) to the TABSQuery.</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabsquery_sql.htm>SQL</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> property. If you'd like a query to return a modifiable records set, set TABSQuery.</span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><a href=tabsquery_requestlive.htm>RequestLive</a></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"> property to True.
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">4.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b><a href=openingdatabases.htm>Connect to a database</a></b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b> (optional).</b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>
<br>
</b></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b></b></span></td><td></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">5. </span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"><b>Execute / Open a query.</b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> You can execute a query in two ways,
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"></td><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">·</font></span></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">If a query returns records set, i.e. SELECT command, set the <a href=tdataset_active.htm>Active</a> property of the query to True, either at design time in the Object Inspector, or in code at runtime: ABSQuery1.Active := True; or call the <a href=tdataset_open.htm>Open</a> method for the query at runtime, ABSQuery1.Open;
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"></td><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">·</font></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">If a query doesn't return records, i.e. INSERT, UPDATE, etc., call the <a href=tabsquery_execsql.htm>ExecSQL</a> method for the query at runtime, ABSQuery1.ExecSQL;<span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100">
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"></td><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"></span></td><td></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#010100"></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
<b>Example:
<br>
</b>
<br>
</span><span style="font-family:Courier New; font-size:8pt; color:#000000"> <span style="font-family:Courier New; font-size:8pt; color:#000080"><i>{set up database component}</i></span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">
<br>
ABSDatabase1.DatabaseName := <span style="font-family:Courier New; font-size:8pt; color:#000080">'emp_db'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">;
<br>
ABSDatabase1.DatabaseFileName := <span style="font-family:Courier New; font-size:8pt; color:#000080">'c:\data\employee_db.abs'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">;
<br>
<br>
<span style="font-family:Courier New; font-size:8pt; color:#000080"><i>{set up query component}</i></span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">
<br>
ABSQuery1.DatabaseName := <span style="font-family:Courier New; font-size:8pt; color:#000080">'emp_db'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">;
<br>
ABSQuery1.SQL.Text := <span style="font-family:Courier New; font-size:8pt; color:#000080">'select * from employee'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">;
<br>
ABSQuery1.RequestLive := True;
<br>
<br>
<b>if</b> (<b>not</b> ABSDatabase1.Exists) <b>then</b>
<br>
<b>raise</b> Exception.Create(<span style="font-family:Courier New; font-size:8pt; color:#000080">'Database file does not exist'</span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">);
<br>
<br>
<span style="font-family:Courier New; font-size:8pt; color:#000080"><i>{execute and open query}</i></span></span><span style="font-family:Courier New; font-size:8pt; color:#000000">
<br>
ABSQuery1.Open;</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
</span></span>
<!--#include virtual="/inc/footer.php"-->
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -