Database Connection, Parameterized Statement

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Database Connection, Parameterized Statement

Hasko Heinecke-2
I'm having problems with ParameterizedStatement in the Database
Connection kit. (Or maybe it's having problems with me. :-)) I'm using
Dolphin 4.01 on NT 4 with MS Access 2000 via ODBC. Here's the code I'm
trying to execute:

stm := connection prepare: 'PARAMETERS StartDate DateTime; SELECT
Price FROM Buys WHERE (((Buys.Date) >= [StartDate]);'.
stm paramCols: (connection
  columns: 'Date'
  qualifier: nil
  owner: nil
  table: 'Buys'.
stm values: (Array with: (Timestamp date: Date today)).
stm exec

In the exec, I'm getting an ODBC exception saying: 'Too few
parameters. Expected 1.' When I inspect the statement before executing
it, the parameter seems to be bound fine. The query works fine when I
don't parameterize it, and the parameterized query runs fine when I
specify it in Access directly.

Is this a known problem? Am I doing something wrong. I'd be grateful
for any help.

Hasko


Reply | Threaded
Open this post in threaded view
|

Re: Database Connection, Parameterized Statement

Dmitry Zamotkin-3
Hello, Hasko

"Hasko Heinecke" <[hidden email]> wrote in message
news:[hidden email]...
> I'm having problems with ParameterizedStatement in the Database
> Connection kit. (Or maybe it's having problems with me. :-)) I'm using
> Dolphin 4.01 on NT 4 with MS Access 2000 via ODBC. Here's the code I'm
> trying to execute:
>

> stm := connection prepare: 'PARAMETERS StartDate DateTime; SELECT
> Price FROM Buys WHERE (((Buys.Date) >= [StartDate]);'.

should be something like:

stm := connection prepare: 'select Price from Buys where Date >= ?'.

> stm paramCols: (connection
>   columns: 'Date'
>   qualifier: nil
>   owner: nil
>   table: 'Buys'.
> stm values: (Array with: (Timestamp date: Date today)).
> stm exec
>
> In the exec, I'm getting an ODBC exception saying: 'Too few
> parameters. Expected 1.'

Yes, you used a wrong syntax and did not put a placeholder ( '?' ) in your
query. Let's read "Preparing SQL for Later Execution" chapter in Education
Centre:

http://www.object-arts.com/Lib/EducationCentre4/htm/preparingsqlforlaterexec
ution.htm

> Hasko

Dmitry


Reply | Threaded
Open this post in threaded view
|

Re: Database Connection, Parameterized Statement

Andy Bower
Hasko,

I don't think you can use Access parameterized queries like this in The DB
Connection. The ParameterizedStatement is intended to be used with ?
placeholders and prepared in Smalltalk (as Dmitry indicates).

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---

"Dmitry Zamotkin" <[hidden email]> wrote in message
news:9imi99$cb7$[hidden email]...

> Hello, Hasko
>
> "Hasko Heinecke" <[hidden email]> wrote in message
> news:[hidden email]...
> > I'm having problems with ParameterizedStatement in the Database
> > Connection kit. (Or maybe it's having problems with me. :-)) I'm using
> > Dolphin 4.01 on NT 4 with MS Access 2000 via ODBC. Here's the code I'm
> > trying to execute:
> >
>
> > stm := connection prepare: 'PARAMETERS StartDate DateTime; SELECT
> > Price FROM Buys WHERE (((Buys.Date) >= [StartDate]);'.
>
> should be something like:
>
> stm := connection prepare: 'select Price from Buys where Date >= ?'.
>
> > stm paramCols: (connection
> >   columns: 'Date'
> >   qualifier: nil
> >   owner: nil
> >   table: 'Buys'.
> > stm values: (Array with: (Timestamp date: Date today)).
> > stm exec
> >
> > In the exec, I'm getting an ODBC exception saying: 'Too few
> > parameters. Expected 1.'
>
> Yes, you used a wrong syntax and did not put a placeholder ( '?' ) in your
> query. Let's read "Preparing SQL for Later Execution" chapter in Education
> Centre:
>
>
http://www.object-arts.com/Lib/EducationCentre4/htm/preparingsqlforlaterexec
> ution.htm
>
> > Hasko
>
> Dmitry
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Database Connection, Parameterized Statement

Hasko Heinecke-2
In reply to this post by Dmitry Zamotkin-3
"Dmitry Zamotkin" <[hidden email]> wrote in message news:<9imi99$cb7$[hidden email]>...
> Hello, Hasko
> > stm := connection prepare: 'PARAMETERS StartDate DateTime; SELECT
> > Price FROM Buys WHERE (((Buys.Date) >= [StartDate]);'.
>
> should be something like:
>
> stm := connection prepare: 'select Price from Buys where Date >= ?'.

[...]

> Yes, you used a wrong syntax and did not put a placeholder ( '?' ) in your
> query. Let's read "Preparing SQL for Later Execution" chapter in Education
> Centre:

You are right, RTFM would have done it... Sorry to bother and thank you for helping.

Hasko