<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'>Sorry
I misunderstood your original post, and yeah the TIBDatabase.GetTablenames is a
much tidier way of doing it. <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>MSSQL
is definitely a lot more flexible with dynamic SQL.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p> </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 10:51 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> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'>actually another/simpler way
than your idea above is to do:-<br>
<br>
IBDatabase1.GetTableNames(sTableList);<br>
then <br>
<br>
if sTableList.indexof('MyTable'); <> -1 then //drop the table<br>
<br>
<br>
<o:p></o:p></p>
<div>
<p class=MsoNormal>On Wed, Jun 17, 2009 at 10:44 AM, Jeremy Coulter <<a
href="mailto:jscoulter@gmail.com">jscoulter@gmail.com</a>> wrote:<o:p></o:p></p>
<p class=MsoNormal>yeah I know how to do it in code thats easy. I was just
trying to do it in SQL.<br>
I am too used to MSSQL I guess :-)<o:p></o:p></p>
<div>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p>
<div>
<p class=MsoNormal>On Wed, Jun 17, 2009 at 10:34 AM, Willie Juson <<a
href="mailto:willie.Juson@satara.co.nz" target="_blank">willie.Juson@satara.co.nz</a>>
wrote:<o:p></o:p></p>
<div>
<div>
<p><span style='color:#1F497D'>Here’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
– which the TIBQuery gets in the absence of a specific one being assigned
to it.</span><o:p></o:p></p>
<p><span style='color:#1F497D'> </span><o:p></o:p></p>
<p><span style='color:#1F497D'> </span><o:p></o:p></p>
<p><span style='color:#1F497D'> </span><o:p></o:p></p>
<p><span style='color:#1F497D'> </span><o:p></o:p></p>
<p><span style='color:#1F497D'> </span><o:p></o:p></p>
<p><span style='color:#1F497D'> l_qry := TIBQuery.Create(nil);</span><o:p></o:p></p>
<p><span style='color:#1F497D'> try</span><o:p></o:p></p>
<p><span style='color:#1F497D'> l_qry.Database :=
DM.IBDBKiwitracker;</span><o:p></o:p></p>
<p><span style='color:#1F497D'>
l_qry.Transaction.StartTransaction;</span><o:p></o:p></p>
<p><span style='color:#1F497D'> try</span><o:p></o:p></p>
<p><span style='color:#1F497D'> l_qry.SQL.Add('select
count(*) from rdb$relations where Upper(RDB$RELATION_NAME) = (''MYTABLE'') ');</span><o:p></o:p></p>
<p><span style='color:#1F497D'> l_qry.Open;</span><o:p></o:p></p>
<p><span style='color:#1F497D'> if
(l_qry.Fields[0].Asinteger > 0) then</span><o:p></o:p></p>
<p><span style='color:#1F497D'> begin</span><o:p></o:p></p>
<p><span style='color:#1F497D'>
l_qry.Close;</span><o:p></o:p></p>
<p><span style='color:#1F497D'>
l_qry.SQL.Clear;</span><o:p></o:p></p>
<p><span style='color:#1F497D'>
l_qry.SQL.Add('drop table MyTable');</span><o:p></o:p></p>
<p><span style='color:#1F497D'>
l_qry.ExecSQL;</span><o:p></o:p></p>
<p><span style='color:#1F497D'> end;</span><o:p></o:p></p>
<p><span style='color:#1F497D'> finally</span><o:p></o:p></p>
<p><span style='color:#1F497D'> if
l_qry.Transaction.InTransaction then</span><o:p></o:p></p>
<p><span style='color:#1F497D'>
l_qry.Transaction.Commit;</span><o:p></o:p></p>
<p><span style='color:#1F497D'> end;</span><o:p></o:p></p>
<p><span style='color:#1F497D'> finally</span><o:p></o:p></p>
<p><span style='color:#1F497D'> FreeAndNil(l_qry);</span><o:p></o:p></p>
<p><span style='color:#1F497D'> end;</span><o:p></o:p></p>
<p><span style='color:#1F497D'> </span><o:p></o:p></p>
<p><span style='color:#1F497D'> </span><o:p></o:p></p>
<p><span style='color:#1F497D'>You might also want to check out a bit how the
RDB$ tables work in interbase…..</span><o:p></o:p></p>
<p><span style='color:#1F497D'> </span><o:p></o:p></p>
<p><span style='color:#1F497D'> </span><o:p></o:p></p>
<div style='border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0cm 0cm 0cm;
border-color:-moz-use-text-color -moz-use-text-color'>
<p><b><span style='font-size:10.0pt'>From:</span></b><span style='font-size:
10.0pt'> <a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a>
[mailto:<a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a>]
<b>On Behalf Of </b>Jeremy Coulter<br>
<b>Sent:</b> Wednesday, 17 June 2009 9:59 a.m.<o:p></o:p></span></p>
<div>
<p class=MsoNormal><span style='font-size:10.0pt'><br>
<b>To:</b> NZ Borland Developers Group - Delphi List<o:p></o:p></span></p>
</div>
<div>
<div>
<p class=MsoNormal><b><span style='font-size:10.0pt'>Subject:</span></b><span
style='font-size:10.0pt'> Re: [DUG] Drop table in Interbase<o:p></o:p></span></p>
</div>
</div>
</div>
<div>
<div>
<p> <o:p></o:p></p>
<p 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 "And" is not
part of the SQL statement.<br>
So what I dont follow is, just doing a "SELECT" 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'
<> '' 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<o:p></o:p></p>
<div>
<p>On Tue, Jun 16, 2009 at 4:05 PM, John Bird <<a
href="mailto:johnkbird@paradise.net.nz" target="_blank">johnkbird@paradise.net.nz</a>>
wrote:<o:p></o:p></p>
<div>
<div>
<p><span style='font-size:10.0pt;color:black'>For a good working example see</span><o:p></o:p></p>
</div>
<div>
<p> <o:p></o:p></p>
</div>
<div>
<p><span style='font-size:10.0pt;color:black'><a href="http://xkcd.com/327/"
target="_blank">http://xkcd.com/327/</a></span><o:p></o:p></p>
</div>
<div>
<p> <o:p></o:p></p>
</div>
<div>
<p><span style='font-size:10.0pt;color:black'>(Standard disclaimer - do
not try this at home!)</span><o:p></o:p></p>
</div>
<div>
<p> <o:p></o:p></p>
</div>
<div>
<p>John<o:p></o:p></p>
</div>
<div>
<p> <o:p></o:p></p>
</div>
<div>
<p>----- Original Message ----- <o:p></o:p></p>
</div>
<blockquote style='border:none;border-left:solid windowtext 1.5pt;padding:0cm 0cm 0cm 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt;
border-color:-moz-use-text-color -moz-use-text-color -moz-use-text-color black'>
<div>
<div>
<p style='background:#E4E4E4;-moz-background-clip: -moz-initial;-moz-background-origin: -moz-initial;
-moz-background-inline-policy: -moz-initial;background-attachment:scroll;
background-position-x:0%;background-position-y:0%'><b><span style='font-size:
10.0pt'>From:</span></b><span style='font-size:10.0pt'> <a
href="mailto:jscoulter@gmail.com" target="_blank" title="jscoulter@gmail.com">Jeremy
Coulter</a> </span><o:p></o:p></p>
</div>
<div>
<p><b><span style='font-size:10.0pt'>To:</span></b><span style='font-size:10.0pt'>
<a href="mailto:delphi@delphi.org.nz" target="_blank"
title="delphi@delphi.org.nz">NZ Borland Developers Group - Delphi List</a> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p><b><span style='font-size:10.0pt'>Sent:</span></b><span style='font-size:
10.0pt'> Tuesday, June 16, 2009 3:35 PM</span><o:p></o:p></p>
</div>
<div>
<p><b><span style='font-size:10.0pt'>Subject:</span></b><span style='font-size:
10.0pt'> Re: [DUG] Drop table in Interbase</span><o:p></o:p></p>
</div>
<div>
<p> <o:p></o:p></p>
</div>
<p style='margin-bottom:12.0pt'>ok cool I will try that.<br>
<br>
Thanks, Jeremy<o:p></o:p></p>
<div>
<p>On Tue, Jun 16, 2009 at 2:54 PM, Edward Koryagin <<a
href="mailto:ed_iv2001@yahoo.co.nz" target="_blank">ed_iv2001@yahoo.co.nz</a>>
wrote:<o:p></o:p></p>
<p><br>
select * from rdb$relations ...<br>
and<br>
DROP TABLE ....<br>
Edward Koryagin<br>
<br>
<br>
--- On Tue, 16/6/09, Jeremy Coulter <<a href="mailto:jscoulter@gmail.com"
target="_blank">jscoulter@gmail.com</a>> wrote:<br>
<br>
> From: Jeremy Coulter <<a href="mailto:jscoulter@gmail.com"
target="_blank">jscoulter@gmail.com</a>><br>
> Subject: [DUG] Drop table in Interbase<br>
> To: "NZ Borland Developers Group - Delphi List" <<a
href="mailto:delphi@delphi.org.nz" target="_blank">delphi@delphi.org.nz</a>><br>
> Received: Tuesday, 16 June, 2009, 1:31 PM<o:p></o:p></p>
<div>
<div>
<p>> Hi all.<br>
> In interbase, how do I drop a table if it already exists?<br>
> I want to check for a table exists and if it does exist,<br>
> drop it.<br>
><br>
> I have Googled, but I cant seem to find anything. I am<br>
> prob. searching wrong :-)<br>
><br>
><br>
> Jeremy<br>
><br>
><o:p></o:p></p>
</div>
</div>
<p>> -----Inline Attachment Follows-----<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><br>
> 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> <o:p></o:p></p>
</div>
</div>
<div class=MsoNormal align=center style='text-align:center'>
<hr size=2 width="100%" align=center>
</div>
<div>
<p>_______________________________________________<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><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> <o:p></o:p></p>
</div>
</div>
</div>
</div>
<p class=MsoNormal><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> </o:p></p>
</div>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>