Skip to Content.
Sympa Menu

freetds - Re: [freetds] Error when using nocount, insert and print statements together.

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Lowden, James K" <LowdenJK AT bernstein.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Error when using nocount, insert and print statements together.
  • Date: Mon, 24 Oct 2005 11:36:52 -0400

> From: M A
> Sent: Friday, October 21, 2005 2:40 PM
>
> The following error is reported when a certain executing a certain
> set of commands in a stored procedure. On the previous version it
> would not execute all the statements but on version 0.63 it reports
> the following error.
>
> Attempt to initiate a new SQL Server operation with results pending.
>
> This is using the stable releaese of freetds: version 0.63
>
> To reproduce the error create the table and stored procedure on
> SQL server using the following code:
>
> create table test_api([updated_date] datetime, [id] int)
>
> create proc testProc
> AS
> BEGIN
> set nocount on
> insert into test_api values(getDate(), 1)
> insert into test_api values(getDate(), 2)
> print 'About to call select'
> select updated_date,id from test_api
> print 'Did the select'
> END
>
> Now call the testProc from freetds using
> dbcmd("exec testProc")
>
> Now call the testProc from freetds using
> dbcmd("exec testProc")
>
> and the error will show up.

Well done. Thank you for that problem report.

The error is somewhere in db-lib. sqsh (which uses ct-lib) does fine.

I have reproduced the error with this script:

<snip>
#! /bin/sh
PWD=${HOME}/projects/freetds.cvs/freetds/build/PWD
BSQLDB=/usr/local/bin/bsqldb

DROP=" drop proc testProc"
CREATE=" create proc testProc
AS
BEGIN
create table #test_api([updated_date] datetime,
[id] int)
set nocount on
insert into #test_api values(getDate(), 1)
insert into #test_api values(getDate(), 2)
print 'About to call select'
select updated_date,id from #test_api
print 'Did the select'
END"
EXEC='exec testProc'

S=$(grep ^SRV ${PWD} | awk -F'=' '{print $2}')
U=$(grep ^UID ${PWD} | awk -F'=' '{print $2}')
P=$(grep ^PWD ${PWD} | awk -F'=' '{print $2}')
D=$(grep ^DB ${PWD} | awk -F'=' '{print $2}')

echo ${BSQLDB} -S $S -U $U -P $P -D testdb $@

printf "%s\nGO\n%s\nGO\n%s\n" "${DROP}" "${CREATE}" "${EXEC}" \
| ${BSQLDB} -S $S -U $U -P $P -D testdb $@
</snip>

As you can see from the output below, dbresults() appears not to set up
the resultset metadata. I haven't yet been able to investigate further.


$ ./nocount.sh -v
...
bsqldb:212: Query:
exec testProc
bsqldb:186: dbsqlsend(): OK
Msg 0, Level 0, State 1
Server 'AC2KAMA0848', Procedure 'testProc', Line 8
About to call select
bsqldb:194: dbsqlok(): OK
bsqldb:289: calling dbresults: OK
Result set 1
Freeing prior allocations
Allocating buffers
Allocating compute buffers
Metadata
col name [...]
------ -----[...]

Data
Retrieving return status... none
@@rowcount not available
Retrieving output parameters... none
bsqldb: Msg 20019, Level 7
Attempt to initiate a new Adaptive Server operation with results pending

--jkl

-----------------------------------------
The information contained in this transmission may be privileged and
confidential and is intended only for the use of the person(s) named
above. If you are not the intended recipient, or an employee or agent
responsible
for delivering this message to the intended recipient, any review,
dissemination,
distribution or duplication of this communication is strictly prohibited. If
you are
not the intended recipient, please contact the sender immediately by reply
e-mail
and destroy all copies of the original message. Please note that we do not
accept
account orders and/or instructions by e-mail, and therefore will not be
responsible
for carrying out such orders and/or instructions. If you, as the intended
recipient
of this message, the purpose of which is to inform and update our clients,
prospects
and consultants of developments relating to our services and products, would
not
like to receive further e-mail correspondence from the sender, please "reply"
to the
sender indicating your wishes. In the U.S.: 1345 Avenue of the Americas, New
York,
NY 10105.




Archive powered by MHonArc 2.6.24.

Top of Page