On Sun Sep 26 02:59:03 2010, mertap@upcmail.cz wrote:
Show quoted text> On Saturday 25 September 2010 23:11:08 Martin J Evans via RT wrote:
> > Hi,
> >
> > I've not tried your code yet but I will get around to it.
> >
> > I suspect you'll find that the MS SQL Server ODBC driver is
> attempting
> > to rearrange your SQL in order to find out what the parameters are
> and
> > failing to come up with the right SQL. You can probably see this if
> you
> > enough about SQL Server and can monitor the SQL being executed or
> you
> > can set DBI_TRACE=15=x.log in your environment and rerun your script
> > then examine the x.log file to see if SQLDescribeParam is failing.
> Try
> > splitting the failing do into a prepare, bind_param and execute and
> > setting the TYPE of each bound parameter to SQL_VARCHAR. See the
> > DBD::ODBC FAQ for examples
> > (
http://search.cpan.org/~mjevans/DBD-ODBC-
> 1.25/FAQ#Why_do_I_get_errors_with
> >_bound_parameters_and_MS_SQL_Server?).
> >
> > I will look at this in more detail but in the mean time you can help
> > yourself and me by trying my suggestion and providing a log.
>
> Martin,
>
> first I have to apologize I was not more careful when looking for bug
> cause/solution; I've relied on google little too much for this one :-)
Not a problem.
Show quoted text> Your suggestion with splitting the code to prep-bind-exec works like a
> charm.
:-)
Show quoted text> As for me, I'm quite happy with this solution, I suppose it won't be a
> problem to handle failing statements this way. So please consider the
> urgency
> of my report rather low.
I would but I don't like rts hanging around.
Show quoted text> There are logs attached gathered with single do() call and another one
> gathered with splitted command. It really looks like SQLDescribeParam
> is not
> able to handle long varchars.
Your log shows:
SQLDescribeParam failed reverting to default SQL bind type -9
07009 [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
42000 [Microsoft][ODBC SQL Server Driver]Syntax error or access violation
It is nothing to do with long varchars it is your SQL which is breaking
the ODBC driver.
SQLPrepare INSERT INTO EventLog (ComputerIDC, EventMessage)
SELECT cs.ComputerIDC, ?
FROM ComputerSlice AS cs
WHERE cs.ComputerSliceID = ?
In order for the SQL Server ODBC driver to work out what the 2
parameters are it attempts to rearrange your SQL into a select for the
parameter columns from a table e.g.,
select a_col from mytable where b_col = ?
SQL Server rearranges it into "select b_col from mytable" and hence
finds out what column b_col is.
In your SQL one of the parameters is a string not related to a column so
SQLDescribeParam fails and DBD::ODBC has no choice to assume a default
(it chose SQL_WCHAR). Then you tried to pass input parameter data of
4002 chrs which is too big for an SQL_WCHAR and hence the HY104 invalid
precision error.
So, although I see why this failed I am slightly surprised DBD::ODBC did
not default the parameter type to SQL_WLONGVARCHAR when it saw the
parameter was > 4000 bytes. I will look into this as it may mean you can
go back to how you had it although the SQLDescribeParam will have to be
called and fail - so slightly more work than specifying a bind type.
Show quoted text> Thanks for your time, I really appreciate your help.
No problem.
I'll try and get back to you soon.
Martin
--
Martin J. Evans
Wetherby, UK