[freetds] [ freetds-Patches-731907 ] Choosing datalength whenbinding fixed types

Arnar Birgisson arnarb at oddi.is
Sun May 4 16:05:16 EDT 2003


Thanks freddy77, this is excellent.
Sorry for the late reply, all this went to my spam folder.

I'm having some other problems though that I'm still trying to diagnose.
This is the case: I have this table and stored procedure (in mssql 7.0)

  CREATE TABLE kerfisnotendur (
  	username nvarchar (20) NOT NULL ,
  	kennitala char (10) NOT NULL ,
  	passw char (20) NOT NULL ,
  	status int NOT NULL ,
  	persistent_data varchar (2048) NULL 
  )
  go
  
  CREATE procedure sp_save_persistentdata
  	@data varchar(2048)
  as
  -- $Id: sp_save_persistentdata.sql,v 1.1 2003/05/02 22:22:09 arnarb
Exp $
  
  update kerfisnotendur set persistent_data = @data
  	where username = user
  go

and I call it from PHP 4.3.2RC2 linked with FreeTDS 0.61 (with your
modified patch applied) with this:

  $var = "some base-64 encoded data";
  $stm = mssql_init("sp_save_persistentdata", $conn);
  mssql_bind($stm, "@data", $var, SQLVARCHAR, false, false, 0);
  mssql_execute($stm,true);

This works fine as long as the string $var is not longer than about 400
characters, as soon as it gets larger I start getting "Stored procedure
execution failed" from PHP. I stepped through mssql_execute in the PHP
source and it correctly calls dbrpcexec, which returns SUCCESS, and then
immediately calls dbsqlok which returns FAIL. Stepping throught dbsqlok
reveals that an "end token" is read from sql server and the call to
tds_process_end returns a failure code. I didn't go any further than
that, except for checking the SQL server logs, which for this operation
contain this:

  2003-05-04 11:46:37.37 ods      Error: 17805, Severity: 18, State: 3
  2003-05-04 11:46:37.37 ods      Invalid buffer received from client..

Any ideas on how to proceed?

This is not critical to me whereas executing the stored procedure via
the php function

  mssql_query("exec sp_save_persistentdata @data = '$data'");

works fine, since it doesnt use the rpc mechanism.

Arnar

> -----Original Message-----
> From: freetds-bounces at lists.ibiblio.org 
> [mailto:freetds-bounces at lists.ibiblio.org] On Behalf Of 
> Frediano Ziglio
> Sent: 3. maí 2003 18:49
> To: FreeTDS Development Group
> Subject: Re: [freetds] [ freetds-Patches-731907 ] Choosing 
> datalength whenbinding fixed types
> 
> 
> Il sab, 2003-05-03 alle 20:12, SourceForge.net ha scritto:
> > Patches item #731907, was opened at 2003-05-03 18:12
> > Message generated for change (Tracker Item Submitted) made 
> by Item Submitter
> > You can respond by visiting: 
> > 
> https://sourceforge.net/tracker/?func=detail&atid=407808&aid=7
> 31907&group_id=33106
> > 
> > Category: db-lib
> > Group: None
> > Status: Open
> > Resolution: None
> > Priority: 5
> > Submitted By: Arnar Birgisson (arnar)
> > Assigned to: Nobody/Anonymous (nobody)
> > Summary: Choosing datalength when binding fixed types
> > 
> > Initial Comment:
> > When binding parameters of fixed-length types in dblib,
> > the parameter "datalen" passed to dbrpcparam should be
> > (almost) ignored.
> > 
> > Current FreeTDS behaviour is to use the datalen
> > parameter to determine how many bytes to copy from the
> > parameter into the rpc message. Sybase and mssql
> > documentation state that for fixed types, datalen
> > should be set to -1, and when freetds passes -1 to
> > memcpy, the application segfaults.
> > 
> > This patch changes param_info_alloc, which is called
> > from dprpcparam, to check if we are dealing with a
> > fixed-size type, and if so, then it uses
> > tds_get_size_by_type to set the relevant member in
> > TDSCOLINFO and pass to memcpy.
> > 
> > In the case of variable-sized types, the original
> > behaviour is pertained.
> > 
> > This should fix my earlier reported bug no. 731810, but
> > I don't know if it breaks anything else.
> 
> Hi Arnar!
> 
> It shouldn't break anything. I modified it and applied.
> 
> freddy77
> 
> 
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
> 




More information about the FreeTDS mailing list