Subject RE: [firebird-support] Fastest way to check if Firebird table exists
Author RB Smissaert
Thanks for alerting me to that, but in my particular situation that won’t
happen.



RBS



_____

From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of Teträm Corp
Sent: 12 May 2009 06:11
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] Fastest way to check if Firebird table
exists








Be careful, your function doesn't make distinction between "not existing
table" and "not granted to select existing table"

Thierry

RB Smissaert a écrit :
>
>
> It looks funny, but this works as well and is slightly faster:
>
> Public Function FirebirdTableExists(strTable As String) As Long
>
> Dim strSQL As String
>
> Dim rs As ADODB.Recordset
>
> 'will give 1 if table exists and has records
>
> 'will give 0 if table exists, but has no records
>
> 'will give -1 if table doesn't exist
>
> '-----------------------------------------------
>
> On Error GoTo ERROROUT
>
> strSQL = "SELECT FIRST 1 NULL FROM " & strTable
>
> Set rs = New ADODB.Recordset
>
> rs.Open strSQL, oADOConn, adOpenForwardOnly, adLockReadOnly, adCmdText
>
> If Not rs.EOF Then
>
> FirebirdTableExists = 1
>
> End If
>
> Exit Function
>
> ERROROUT:
>
> FirebirdTableExists = -1
>
> End Function
>
> RBS
>
> _____
>
> From: firebird-support@ <mailto:firebird-support%40yahoogroups.com>
yahoogroups.com
> <mailto:firebird-support%40yahoogroups.com>
> [mailto:firebird-support@ <mailto:firebird-support%40yahoogroups.com>
yahoogroups.com
> <mailto:firebird-support%40yahoogroups.com>] On Behalf Of Teträm Corp
> Sent: 11 May 2009 23:00
> To: firebird-support@ <mailto:firebird-support%40yahoogroups.com>
yahoogroups.com
> <mailto:firebird-support%40yahoogroups.com>
> Subject: Re: [firebird-support] Fastest way to check if Firebird table
> exists
>
> Hi,
>
> I think a better way is to use
>
> select 1 from rdb$relations where rdb$relation_name = :strTable
>
> and may be add "and rdb$relation_blr is null" (or kind of) to exclude
> views
>
> Thierry
>
> RB Smissaert a écrit :
> >
> >
> > Need a fast function in VB that checks if a Firebird (1.5) table
> > exists and
> > came up with:
> >
> > Public Function FirebirdTableExists(strTable As String) As Long
> >
> > Dim strSQL As String
> > Dim rs As ADODB.Recordset
> >
> > 'will give 1 if table exists and has records
> > 'will give 0 if table exists, but has no records
> > 'will give -1 if table doesn't exist
> > '-----------------------------------------------
> > On Error GoTo ERROROUT
> >
> > strSQL = "SELECT FIRST 1 RDB$DB_KEY FROM " & strTable
> >
> > Set rs = New ADODB.Recordset
> > rs.Open strSQL, oADOConn, adOpenForwardOnly, adLockReadOnly, adCmdText
> >
> > If Not rs.EOF Then
> > FirebirdTableExists = 1
> > End If
> >
> > Exit Function
> > ERROROUT:
> >
> > FirebirdTableExists = -1
> >
> > End Function
> >
> > Anything wrong with this or any suggestions for something better?
> >
> > RBS
> >
> >
>
> [Non-text portions of this message have been removed]
>
>





[Non-text portions of this message have been removed]