Board index » delphi » Command objects, forward-only cursors, and EmptyParam

Command objects, forward-only cursors, and EmptyParam

At the end of this post is a very useful piece of advice from Alejandro Mesa, posted a couple of weeks ago in microsoft.public.data.ado.  It explains how to obtain a recordset from a parameterised query, using the command object in a way that works around the normal limitation of a firehose cursor.

The only problem for me is that it's in VB, and I'm getting really frustrated trying to get Delphi to do the same thing.  The specific piece of code that I have trouble with is ostensibly very simple:

  rs.Open cmd, , adOpenStatic, adLockBatchOptimistic
This is a VB call to recordset.open, using as the Source (first) argument an existing command object.

The second argument is missing - the MS help says quite specifically that you must not attempt to define a connection at this point, if you're using a commnad object as your source.

The fifth argument is also missing - MS 'imply' that the Options argument is not used when a command object is supplied.

Now - I can replicate this in Delphi (exactly as above, plus a couple of enclosing parentheses) with late binding.  But the following fails, with late binding:

  rs.Open( cmd, EmptyParam, adOpenStatic, adLockBatchOptimistic)

It returns with the inconsistent / incompatible / missing arguments error message. Why does it fail?  Isn't EmptyParam advertised as being equivalent to an optional parameter not being supplied?

And what I really want to do is get it work with *early* binding, which is where EmptyParam would appear to be mandatory.
For anyone motivated to try this out, I've discovered that the fifth (Options) argument, with early binding, just needs to be set to whatever the type of your command object may be - that was easy.  So the ultimate question - what does the second argument of the following early-bound call need to be?

  rs.Open( cmd, ?????, adOpenStatic, adLockBatchOptimistic, adCmdStoredProc)

'cos EmptyParam doesn't work :-)

Any ideas / thoughts?

Roger Morton
roger.mor...@dial.pipex.com

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Post from Alejandro Mesa in microsoft.public.data.ado on 29 February

Create the command, add parameters, assign value to the parameters and use the command object as recordset source.

Example:

Private Sub Command1_Click()
  Dim cn As ADODB.Connection
  Dim cmd As ADODB.Command
  Dim rs As ADODB.Recordset

  On Error GoTo ErrorHandler

  Set cn = New ADODB.Connection
  Set cmd = New ADODB.Command
  Set rs = New ADODB.Recordset

  cn.Provider = "sqloledb"
  cn.ConnectionString = "data source=alexander;" & _                         "initial catalog=northwind;" & _                         "user id=sa;password=;"
  cn.Errors.Clear
  cn.Open

  cmd.ActiveConnection = cn
  cmd.CommandText = "sp_test"
  cmd.CommandType = adCmdStoredProc

  rs.CursorLocation = adUseClient
  rs.Open cmd, , adOpenStatic, adLockBatchOptimistic

ExitSub:
  On Error Resume Next
  rs.Close
  cn.Close
  Set rs = Nothing
  Set cmd = Nothing
  Set cn = Nothing

  Exit Sub

ErrorHandler:
  MsgBox Err.Number & vbCrLf & _
        Err.Description

  Resume ExitSub
End Sub
+++++++++++++++++++++++++++++++++++++++++++++++++++++

 

Re:Command objects, forward-only cursors, and EmptyParam


Try using Unassigned rather than EmptyParam
Jason Swager

Quote
Roger Morton <roger.mor...@nospamdial.pipex.com> wrote in message

news:RA15D20AB5@LOFT...
Quote
> At the end of this post is a very useful piece of advice from Alejandro

Mesa, posted a couple of weeks ago in microsoft.public.data.ado.  It
explains how to obtain a recordset from a parameterised query, using the
command object in a way that works around the normal limitation of a
firehose cursor.
Quote

> The only problem for me is that it's in VB, and I'm getting really

frustrated trying to get Delphi to do the same thing.  The specific piece of
code that I have trouble with is ostensibly very simple:
Quote

>   rs.Open cmd, , adOpenStatic, adLockBatchOptimistic

> This is a VB call to recordset.open, using as the Source (first) argument

an existing command object.
Quote

> The second argument is missing - the MS help says quite specifically that

you must not attempt to define a connection at this point, if you're using a
commnad object as your source.
Quote

> The fifth argument is also missing - MS 'imply' that the Options argument

is not used when a command object is supplied.
Quote

> Now - I can replicate this in Delphi (exactly as above, plus a couple of

enclosing parentheses) with late binding.  But the following fails, with
late binding:
Quote

>   rs.Open( cmd, EmptyParam, adOpenStatic, adLockBatchOptimistic)

> It returns with the inconsistent / incompatible / missing arguments error

message. Why does it fail?  Isn't EmptyParam advertised as being equivalent
to an optional parameter not being supplied?
Quote

> And what I really want to do is get it work with *early* binding, which is

where EmptyParam would appear to be mandatory.
Quote

> For anyone motivated to try this out, I've discovered that the fifth

(Options) argument, with early binding, just needs to be set to whatever the
type of your command object may be - that was easy.  So the ultimate
question - what does the second argument of the following early-bound call
need to be?
Quote

>   rs.Open( cmd, ?????, adOpenStatic, adLockBatchOptimistic,
adCmdStoredProc)

> 'cos EmptyParam doesn't work :-)

> Any ideas / thoughts?

> Roger Morton
> roger.mor...@dial.pipex.com

> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Post from Alejandro Mesa in microsoft.public.data.ado on 29 February

> Create the command, add parameters, assign value to the parameters and use

the command object as recordset source.

- Show quoted text -

Quote

> Example:

> Private Sub Command1_Click()
>   Dim cn As ADODB.Connection
>   Dim cmd As ADODB.Command
>   Dim rs As ADODB.Recordset

>   On Error GoTo ErrorHandler

>   Set cn = New ADODB.Connection
>   Set cmd = New ADODB.Command
>   Set rs = New ADODB.Recordset

>   cn.Provider = "sqloledb"
>   cn.ConnectionString = "data source=alexander;" & _

"initial catalog=northwind;" & _                         "user
id=sa;password=;"

- Show quoted text -

Quote
>   cn.Errors.Clear
>   cn.Open

>   cmd.ActiveConnection = cn
>   cmd.CommandText = "sp_test"
>   cmd.CommandType = adCmdStoredProc

>   rs.CursorLocation = adUseClient
>   rs.Open cmd, , adOpenStatic, adLockBatchOptimistic

> ExitSub:
>   On Error Resume Next
>   rs.Close
>   cn.Close
>   Set rs = Nothing
>   Set cmd = Nothing
>   Set cn = Nothing

>   Exit Sub

> ErrorHandler:
>   MsgBox Err.Number & vbCrLf & _
>         Err.Description

>   Resume ExitSub
> End Sub
> +++++++++++++++++++++++++++++++++++++++++++++++++++++

Re:Command objects, forward-only cursors, and EmptyParam


Using late-binding, have you tried leaving the parameter unspecified
just as it is done in the VB example?

  rs.Open( cmd, , adOpenStatic, adLockBatchOptimistic,
adCmdStoredProc)

On Thu, 23 Mar 2000 16:24:33 GMT, roger.mor...@nospamdial.pipex.com

Quote
(Roger Morton) wrote:
>At the end of this post is a very useful piece of advice from Alejandro Mesa, posted a couple of weeks ago in microsoft.public.data.ado.  It explains how to obtain a recordset from a parameterised query, using the command object in a way that works around the normal limitation of a firehose cursor.

>The only problem for me is that it's in VB, and I'm getting really frustrated trying to get Delphi to do the same thing.  The specific piece of code that I have trouble with is ostensibly very simple:

>  rs.Open cmd, , adOpenStatic, adLockBatchOptimistic

>This is a VB call to recordset.open, using as the Source (first) argument an existing command object.

>The second argument is missing - the MS help says quite specifically that you must not attempt to define a connection at this point, if you're using a commnad object as your source.

>The fifth argument is also missing - MS 'imply' that the Options argument is not used when a command object is supplied.

>Now - I can replicate this in Delphi (exactly as above, plus a couple of enclosing parentheses) with late binding.  But the following fails, with late binding:

>  rs.Open( cmd, EmptyParam, adOpenStatic, adLockBatchOptimistic)

>It returns with the inconsistent / incompatible / missing arguments error message. Why does it fail?  Isn't EmptyParam advertised as being equivalent to an optional parameter not being supplied?

>And what I really want to do is get it work with *early* binding, which is where EmptyParam would appear to be mandatory.

>For anyone motivated to try this out, I've discovered that the fifth (Options) argument, with early binding, just needs to be set to whatever the type of your command object may be - that was easy.  So the ultimate question - what does the second argument of the following early-bound call need to be?

>  rs.Open( cmd, ?????, adOpenStatic, adLockBatchOptimistic, adCmdStoredProc)

>'cos EmptyParam doesn't work :-)

>Any ideas / thoughts?

>Roger Morton
>roger.mor...@dial.pipex.com

>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>Post from Alejandro Mesa in microsoft.public.data.ado on 29 February

>Create the command, add parameters, assign value to the parameters and use the command object as recordset source.

>Example:

>Private Sub Command1_Click()
>  Dim cn As ADODB.Connection
>  Dim cmd As ADODB.Command
>  Dim rs As ADODB.Recordset

>  On Error GoTo ErrorHandler

>  Set cn = New ADODB.Connection
>  Set cmd = New ADODB.Command
>  Set rs = New ADODB.Recordset

>  cn.Provider = "sqloledb"
>  cn.ConnectionString = "data source=alexander;" & _                         "initial catalog=northwind;" & _                         "user id=sa;password=;"
>  cn.Errors.Clear
>  cn.Open

>  cmd.ActiveConnection = cn
>  cmd.CommandText = "sp_test"
>  cmd.CommandType = adCmdStoredProc

>  rs.CursorLocation = adUseClient
>  rs.Open cmd, , adOpenStatic, adLockBatchOptimistic

>ExitSub:
>  On Error Resume Next
>  rs.Close
>  cn.Close
>  Set rs = Nothing
>  Set cmd = Nothing
>  Set cn = Nothing

>  Exit Sub

>ErrorHandler:
>  MsgBox Err.Number & vbCrLf & _
>        Err.Description

>  Resume ExitSub
>End Sub
>+++++++++++++++++++++++++++++++++++++++++++++++++++++

Re:Command objects, forward-only cursors, and EmptyParam


In <38da5ec6.1574...@forums.inprise.com>, (Marjan Venema) hastily scribbled:

Quote

> Using late-binding, have you tried leaving the parameter unspecified
> just as it is done in the VB example?

>   rs.Open( cmd, , adOpenStatic, adLockBatchOptimistic,
> adCmdStoredProc)

Yes I have - in fact that's the only version of life that, for the moment, I know does work :-)

Incidentally, I've now discovered another limitation of this workaround - you cannot use server side cursors.

Roger Morton
roger.mor...@dial.pipex.com

Re:Command objects, forward-only cursors, and EmptyParam


In <8bdmta$f...@bornews.borland.com>, "Jason Swager" hastily scribbled:

Quote

> Try using Unassigned rather than EmptyParam
> Jason Swager

Thanks for the thought. I'm afraid it produces the same error, both with early and late binding

Roger Morton
roger.mor...@dial.pipex.com

Other Threads