Subject | RE: [firebird-support] Fastest way to check if Firebird table exists |
---|---|
Author | RB Smissaert |
Post date | 2009-05-11T20:05:11Z |
Ok, this is better as getting the RDB$DB_KEY is not the fastest one to get,
so if you know a field then that is better:
Public Function FirebirdTableExists(strTable As String, _
Optional strField As String =
"RDB$DB_KEY") 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 " & strField & " 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@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of RB Smissaert
Sent: 11 May 2009 19:48
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Fastest way to check if Firebird table exists
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]
so if you know a field then that is better:
Public Function FirebirdTableExists(strTable As String, _
Optional strField As String =
"RDB$DB_KEY") 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 " & strField & " 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@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of RB Smissaert
Sent: 11 May 2009 19:48
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Fastest way to check if Firebird table exists
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]