[egenix-users] String or binary data would be truncated

eGenix Support support at egenix.com
Tue Mar 6 22:59:06 CET 2007


Am 06.03.2007, 20:35 Uhr, schrieb Programmer  
<programmer at paradigm-corp.com>:

> Warning: ('22001', 8152, '[Microsoft][ODBC SQL Server Driver][SQL
> Server]String or binary data would be truncated.', 6113)

The key here is that the error message is coming from the MS SQL server.  
It looks to me like one of the parameters is longer than a defined field  
and is, thus, correctly rejected by the database.

> Here is the script dieFiles:
> parameters = files, dieID
> sqlMethod = context.addDieFiles

> f = str(files).split(',')if files is not None:
>     for j in f:
>         sqlMethod(ID=dieID, fname=str(j))

Eek! That's worse than some of the stuff I come up with! ;-)

You can use the :list suffix on a form variable name to ensure you get a  
list. Or you can also use the same_type() (or something like this) call in  
a PythonScript to determine whether you have a list. Either of these will  
tidy up your code meaning less throwaway varibales that can bite in the  
future.

if not same_type([], files):
      files = list(files)
for f in files:
     sqlMethod(ID=dieID, fname=f)

> The form allows the user to select a single file for the "order form".
> This filename goes into the Dies table. At the bottom of the form the
> user can select several files for "art work" and these filenames are
> then inserted into the dieFiles table which is FKed to the Dies table.
> In my tests the insert is successful if I choose an order form and not
> an art work file. I thought I was having one of those Zope errors due to
> the format of the values. These look as such:
> order_form value - 	'C:\\Documents and Settings\\Programmer\\My
> Documents\\Code\\blinkingBox.txt'
> fileList value with one file selected - 	'C:\\Documents and
> Settings\\Programmer\\My Documents\\Code\\copyFields.txt'
> fileList value with multiple files - 	['C:\\Documents and
> Settings\\Programmer\\My Documents\\Code\\caveman.txt', 'C:\\Documents
> and Settings\\Programmer\\My Documents\\Code\\CATEGORY.txt']
> As you can see the fileList value with one file selected is the same as
> from order_form which does insert successfully on it's own. What gives
> here?
> Is this a freak of nature? A SQL Server hiccup? my sloppy code? or
> mxODBCZopeDA.ZopeDA? help!

You should check the SQL logs to see exactly which value is causing the  
problem.

Charlie
-- 
Charlie Clark
eGenix.com

Professional Python Services directly from the Source
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
Try mxODBC.Zope.DA for Windows, Mac OS, Linux, Solaris, FreeBSD for free!



More information about the egenix-users mailing list