Oracle 7.3 and Oracle 8i with Visual Basic

Oracle 7.3 and Oracle 8i with Visual Basic

Post by Glen » Fri, 22 Mar 2002 00:14:04



I've got an interesting scenario here. The following code works
perfectly against Oracle 7.3 database using DAO. (It's outdated code
and we need to migrate this code to Oracle 8i)

The query is stored in the sring known as S. The query returns results
on the final command line:

    Set SelectSQL = qdf.OpenRecordset(dbOpenSnapshot)

This returns SelectSQL back to the original source as a recordset.
Yet, it works perfectly on Oracle 7.3 database using ODBC Microsoft
Driver 2.5 for Oracle, Oracle Driver 7.3 and 8.0 driver.

There are problems with other drivers. Microsoft ODBC 2.5 driver for
Oracle seems to work best but in checking out the recordcount -
SelectSQL.RecordCount returns a value of -1.

So I'm asking - are querydefs incompatible with 8i? I made the
recommendation of overhauling the code to ADO (a lot of code)

Any suggestions how we can 'fix' this as a crutch in order to make
this a smooth but temp solution to 8i? Thanks! See code below:

Function SelectSQL(s As String) As Recordset
'--------------------------------------------------------------------
'   Purpose:     Runs as SELECT SQL query.
'
'   Returns:     A recordset containing the results of the query.
'--------------------------------------------------------------------
    On Error GoTo SelectSqlError
    Dim qdf As QueryDef
    Dim i As Long

    Set qdf = con.CreateQueryDef("")
    qdf.SQL = s
    qdf.MaxRecords = 0

    i = con.CreateQueryDef("", "SELECT COUNT(*) " _
        & Right$(s, Len(s) - (InStr(1, UCase$(s), "FROM") - 1))) _
        .OpenRecordset(dbOpenSnapshot).Fields(0)

    If i < 1 Then i = 1
    qdf.CacheSize = i

    Set SelectSQL = qdf.OpenRecordset(dbOpenSnapshot)

    Exit Function
'--------------------------------------

SelectSqlError:
      MsgBox "Function SelectSQL is Unable to run query: " &
LCase$(s), _
        vbCritical, Err.Number & " - " & Err.Description
End Function

 
 
 

Oracle 7.3 and Oracle 8i with Visual Basic

Post by Frank Shult » Wed, 27 Mar 2002 11:57:23


Actually, this behavior is by design.  The recordset object doesn't 'know'
how many records it has.  The -1 means 'True' as in it has records.  You
have to invoke the .MoveLast then .MoveFirst methods to get an actual
recordcount.  This may/may not work depending on the CursorType when the
Recordset was opened.
  I would suggest writing a proc that with an output parameter that returns
the number of records.  It'll be a lot easier for you.
  Frank.

Quote:> I've got an interesting scenario here. The following code works
> perfectly against Oracle 7.3 database using DAO. (It's outdated code
> and we need to migrate this code to Oracle 8i)

> The query is stored in the sring known as S. The query returns results
> on the final command line:

>     Set SelectSQL = qdf.OpenRecordset(dbOpenSnapshot)

> This returns SelectSQL back to the original source as a recordset.
> Yet, it works perfectly on Oracle 7.3 database using ODBC Microsoft
> Driver 2.5 for Oracle, Oracle Driver 7.3 and 8.0 driver.

> There are problems with other drivers. Microsoft ODBC 2.5 driver for
> Oracle seems to work best but in checking out the recordcount -
> SelectSQL.RecordCount returns a value of -1.

> So I'm asking - are querydefs incompatible with 8i? I made the
> recommendation of overhauling the code to ADO (a lot of code)

> Any suggestions how we can 'fix' this as a crutch in order to make
> this a smooth but temp solution to 8i? Thanks! See code below:

> Function SelectSQL(s As String) As Recordset
> '--------------------------------------------------------------------
> '   Purpose:     Runs as SELECT SQL query.
> '
> '   Returns:     A recordset containing the results of the query.
> '--------------------------------------------------------------------
>     On Error GoTo SelectSqlError
>     Dim qdf As QueryDef
>     Dim i As Long

>     Set qdf = con.CreateQueryDef("")
>     qdf.SQL = s
>     qdf.MaxRecords = 0

>     i = con.CreateQueryDef("", "SELECT COUNT(*) " _
>         & Right$(s, Len(s) - (InStr(1, UCase$(s), "FROM") - 1))) _
>         .OpenRecordset(dbOpenSnapshot).Fields(0)

>     If i < 1 Then i = 1
>     qdf.CacheSize = i

>     Set SelectSQL = qdf.OpenRecordset(dbOpenSnapshot)

>     Exit Function
> '--------------------------------------

> SelectSqlError:
>       MsgBox "Function SelectSQL is Unable to run query: " &
> LCase$(s), _
>         vbCritical, Err.Number & " - " & Err.Description
> End Function


 
 
 

1. Oracle Database Access 7.3 and Visual Basic 4.0 16bits

URGENT :

We have connection problems with an Oracle Database Engine using ODBC while
being in the Visual Basic v4.0 16 bits Environnement (Debug Mode). The
message is that there seems to be an TNS resolve problem.

We observed that a smaller project seems to work properly.

What seems to be strange, is that the executables do not have this problem.

Any suggestions or questions will be appreciated.

Robbert de GROOT

2. Removing/changing Grid highlights

3. visual basic, odbc, oracle 7.3

4. Using "Delete" SQL statement in VB6 connecting to Access DB

5. Visual Basic to Oracle 7.3

6. Paradox OF THE UN-LOCKING RECORDS

7. IA-Cedar Rapids Area-263612--DB2-Visual Basic-ORACLE-DB2,Visual Basic and Oracle

8. hardware requirement for sql7

9. NY-New York City-113309--ORACLE-Visual Basic-SQL-Visual Basic / Oracle Developer

10. IL-Chicago-47740--Programming Skills-Visual Basic-ORACLE-DBMS-MS ACCESS-Programmer-Visual Basic + Oracle

11. GA-Decatur-99898--Visual Basic-ORACLE-Windows-DOS-Programmer-Visual Basic/Oracle

12. 22685-AL-HUNTSVILLE-Visual Basic-ORACLE-Visual Basic and Oracle