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.