Hi, all.

I use ActivePerl 5.8.8.817 with the latest Class::DBI::MSSQL, DBD::ODBC on Win2000 sp4. Connecting to MS SQL Server 2000.

Here is the issue:

DBI has very handy 'has_many' relationship. Upon adding new record with add_to_WHAT_WE_HAVE_MANY, 'MakeNewObj' accessor is internally called. This accessor is created using Class::DBI->set_sql(). Which calls Ima::DBI->set_sql() and finally DBI->prepare_cached().

Here is an example of SQL generated this way upon insertion values '2', 'Log', '3', 'artem2' into t_PostParams table (taken from profiler):
declare @P1 int set @P1=8 exec sp_prepexec @P1 output, N'@P1 bigint,@P2 nvarchar(3),@P3 bigint,@ +P4 nvarchar(6)', N'INSERT INTO t_PostParams (po_id, pp_name, pp_id, p +p_value) VALUES (@P1, @P2, @P3, @P4) ', 2, N'Log', 3, N'artem2' select @P1
So far, so good.

Now, I call add_to_post_params() one more time. Another record is being added. But no more statement is generated this time! The above one is used instead with the new data values:
exec sp_execute 8, 2, N'passwd', 4, N'121'
The result is obviously bad. There is (2, pas, 4, 121) record stored instead of (2, passwd, 4, 121). Mind that actual size of pp_name is 50.

My questions are:
1. Isn't it weird, that it generates sql according to the size of values being put instead of real field sizes?
2. If it is not. Shouldn't it cook another statement when sizes differ?
3. If it is not. There is a way to tell set_sql() to use prepare() instead of prepare_cached(), but I didn't find how to control this using CDBI interface. Any hints?

Thanks,
Artem A. Avetisyan.

In reply to DBI->prepare_cached() by artemave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.