<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Arial","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>Here&#8217;s
some quick and dirty code that works (it probably wants some exception handling
added around the ExecSQL), but hopefully you get the gist of it, in this
example the database DM.IBDBKiwitracker is a TIBDatabase component on our
central Datamodule unit for our application. It assumes the Database has a
default transaction assigned &#8211; which the TIBQuery gets in the absence of a
specific one being assigned to it.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;
l_qry := TIBQuery.Create(nil);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;
try<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
l_qry.Database := DM.IBDBKiwitracker;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
l_qry.Transaction.StartTransaction;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
try<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
l_qry.SQL.Add('select count(*) from rdb$relations where
Upper(RDB$RELATION_NAME) = (''MYTABLE'') ');<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
l_qry.Open;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (l_qry.Fields[0].Asinteger &gt; 0) then<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
begin<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
l_qry.Close;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
l_qry.SQL.Clear;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
l_qry.SQL.Add('drop table MyTable');<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
l_qry.ExecSQL;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
end;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
finally<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if l_qry.Transaction.InTransaction then<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
l_qry.Transaction.Commit;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
end;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;
finally<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
FreeAndNil(l_qry);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>&nbsp;
end;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>You
might also want to check out a bit how the RDB$ tables work in interbase&#8230;..<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
delphi-bounces@delphi.org.nz [mailto:delphi-bounces@delphi.org.nz] <b>On Behalf
Of </b>Jeremy Coulter<br>
<b>Sent:</b> Wednesday, 17 June 2009 9:59 a.m.<br>
<b>To:</b> NZ Borland Developers Group - Delphi List<br>
<b>Subject:</b> Re: [DUG] Drop table in Interbase<o:p></o:p></span></p>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'>Thansk for your reply edward.
However, I dont normall use Interbase and your example didnt make a lot of
sence. I managed to find a similar example but I dont follow part of it.<br>
<br>
when I run :<br>
<br>
select * from rdb$relations WHERE RDB$RELATION_NAME = 'MyTable'<br>
and<br>
DROP TABLE MyTable;<br>
COMMIT;<br>
<br>
It tells me DROP is an invalid token. So I assume the &quot;And&quot; is not
part of the SQL statement.<br>
So what I dont follow is, just doing a &quot;SELECT&quot; to see if a record
exists then dropping the table seems like something is missing.<br>
<br>
in a programming sense, I would expect something like<br>
<br>
IF select * from rdb$relations WHERE RDB$RELATION_NAME = 'MyTable'&nbsp;
&lt;&gt; '' then<br>
DROP TABLE MyTable;<br>
<br>
I know thats not real code, but my point is, just because I can do a select,
doesnt tell me if the table exists or not to try to delete it.......I hope you
follow what I am meaning.<br>
<br>
Jeremy<br>
<br>
<o:p></o:p></p>

<div>

<p class=MsoNormal>On Tue, Jun 16, 2009 at 4:05 PM, John Bird &lt;<a
href="mailto:johnkbird@paradise.net.nz">johnkbird@paradise.net.nz</a>&gt;
wrote:<o:p></o:p></p>

<div>

<div>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";
color:black'>For a good working example see</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";
color:black'><a href="http://xkcd.com/327/" target="_blank">http://xkcd.com/327/</a></span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";
color:black'>(Standard disclaimer&nbsp;- do not try this at home!)</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>John<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>----- Original Message ----- <o:p></o:p></p>

</div>

<blockquote style='border:none;border-left:solid black 1.5pt;padding:0cm 0cm 0cm 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'>

<div>

<div>

<p class=MsoNormal style='background:#E4E4E4'><b><span style='font-size:10.0pt;
font-family:"Arial","sans-serif"'>From:</span></b><span style='font-size:10.0pt;
font-family:"Arial","sans-serif"'> <a href="mailto:jscoulter@gmail.com"
target="_blank" title="jscoulter@gmail.com">Jeremy Coulter</a> <o:p></o:p></span></p>

</div>

<div>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>To:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> <a
href="mailto:delphi@delphi.org.nz" target="_blank" title="delphi@delphi.org.nz">NZ
Borland Developers Group - Delphi List</a> <o:p></o:p></span></p>

</div>

</div>

<div>

<div>

<div>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Sent:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> Tuesday, June 16,
2009 3:35 PM<o:p></o:p></span></p>

</div>

<div>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Subject:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> Re: [DUG] Drop table
in Interbase<o:p></o:p></span></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<p class=MsoNormal style='margin-bottom:12.0pt'>ok cool I will try that.<br>
<br>
Thanks, Jeremy<o:p></o:p></p>

<div>

<p class=MsoNormal>On Tue, Jun 16, 2009 at 2:54 PM, Edward Koryagin &lt;<a
href="mailto:ed_iv2001@yahoo.co.nz" target="_blank">ed_iv2001@yahoo.co.nz</a>&gt;
wrote:<o:p></o:p></p>

<p class=MsoNormal><br>
select * from rdb$relations ...<br>
and<br>
DROP TABLE ....<br>
Edward Koryagin<br>
<br>
<br>
--- On Tue, 16/6/09, Jeremy Coulter &lt;<a href="mailto:jscoulter@gmail.com"
target="_blank">jscoulter@gmail.com</a>&gt; wrote:<br>
<br>
&gt; From: Jeremy Coulter &lt;<a href="mailto:jscoulter@gmail.com"
target="_blank">jscoulter@gmail.com</a>&gt;<br>
&gt; Subject: [DUG] Drop table in Interbase<br>
&gt; To: &quot;NZ Borland Developers Group - Delphi List&quot; &lt;<a
href="mailto:delphi@delphi.org.nz" target="_blank">delphi@delphi.org.nz</a>&gt;<br>
&gt; Received: Tuesday, 16 June, 2009, 1:31 PM<o:p></o:p></p>

<div>

<div>

<p class=MsoNormal>&gt; Hi all.<br>
&gt; In interbase, how do I drop a table if it already exists?<br>
&gt; I want to check for a table exists and if it does exist,<br>
&gt; drop it.<br>
&gt;<br>
&gt; I have Googled, but I cant seem to find anything. I am<br>
&gt; prob. searching wrong :-)<br>
&gt;<br>
&gt;<br>
&gt; Jeremy<br>
&gt;<br>
&gt;<o:p></o:p></p>

</div>

</div>

<p class=MsoNormal>&gt; -----Inline Attachment Follows-----<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; NZ Borland Developers Group - Delphi mailing list<br>
&gt; Post: <a href="mailto:delphi@delphi.org.nz" target="_blank">delphi@delphi.org.nz</a><br>
&gt; Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi"
target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
&gt; Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz"
target="_blank">delphi-request@delphi.org.nz</a><br>
&gt; with Subject: unsubscribe<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@delphi.org.nz" target="_blank">delphi@delphi.org.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz"
target="_blank">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<o:p></o:p></p>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</div>

<div class=MsoNormal align=center style='text-align:center'>

<hr size=2 width="100%" align=center>

</div>

<div>

<p class=MsoNormal>_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@delphi.org.nz" target="_blank">delphi@delphi.org.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz"
target="_blank">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<o:p></o:p></p>

</div>

</blockquote>

</div>

<p class=MsoNormal><br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a>
with Subject: unsubscribe<o:p></o:p></p>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</body>

</html>