iic has asked for the wisdom of the Perl Monks concerning the following question:

open FILE,"<e:\\test.html" || die "Can not open file.";
while($line=<FILE>){$content.=$line}
close FILE;
$content=~s/\'/\'\'/g;
......
$SQL=<<SQL;
begin tran
create table xxx
(n char(100),
t text)
insert xxx
values('abc','$content')
commit tran
SQL
if($db->Sql($SQL)){print "error1\n";exit;}
$SQL=<<SQL;
begin tran
select * from xxx
commit tran
SQL
if($db->Sql($SQL)){print "error2\n";exit;}
if($db->FetchRow())
{
$data=$db->Data();
print "$data\n";###when <= 10,467
}
else
{
print "no line\n";###when > 10,467
exit;
}
When the size of test.html is larger than 10,467 bytes,
its results is "no line".
Can you tell me why?
thanks.

Replies are listed 'Best First'.
Re: FetchRow
by c-era (Curate) on Jul 26, 2000 at 15:46 UTC
    There are limitations to how much a field can hold in SQL. Different SQLs allow different lengths of information to be entered. You want to make sure that your SQL server can handle a value greater then 10,467 bytes.
Re: FetchRow
by johannz (Hermit) on Jul 27, 2000 at 00:56 UTC

    First, a potential warning: Most database interfaces have a max size for the the SQL statement to be processed. You might run into that with the first query eventually. Look and see if Win32::ODBC supports the concept of Bind variables.
    Or check out DBD::ODBC, which would making future porting easier.

    Second, the issue likely is not the whether the column can support the data, because I think the 'text' column type can support up to 2 GB (IIRC). The issue is more likely to be in the database driver. Have you went in with another tool to see if the data was added, and whether that tool can pull it up? If it can, you will have to read the Win32::ODBC documentation. Here is a peice of it(from the ActivePerl 5.6 port):

    And what are the benefits of this module?
    • The number of ODBC connections is limited by memory and ODBC itself (have as many as you want!).
    • The working limit for the size of a field is 10,240 bytes, but you can increase that limit (if needed) to a max of 2,147,483,647 bytes. (You can always recompile to increase the max limit.)
    • You can open a connection by either specifing a DSN or a connection string!
    • You can open and close the connections in any order!
    • Other things that I can not think of right now... :)
    In particular this piece seems relevant:
    SetMaxBufSize ( SIZE )
    This sets the MaxBufSize for a particular connection. This will most likely never be needed but...
    The amount of memory that is allocated to retrieve the field data of a record is dynamic and changes when it need to be larger. I found that a memo field in an MS Access database ended up requesting 4 Gig of space. This was a bit much so there is an imposed limit (2,147,483,647 bytes) that can be allocated for data retrieval.
    Since it is possible that someone has a database with field data greater than 10,240, you can use this function to increase the limit up to a ceiling of 2,147,483,647 (recompile if you need more).
    Returns the max number of bytes.
    Hope this helps.
RE: FetchRow
by le (Friar) on Jul 26, 2000 at 16:04 UTC
    I repost the code to make it more readable:
    open FILE,"<e:\\test.html" || die "Can not open file."; while($line=<FILE>) {$content.=$line} close FILE; $content=~s/\'/\'\'/g; ...... $SQL=<<SQL; begin tran create table xxx (n char(100), t text) insert xxx values('abc','$content') commit tran SQL if ($db->Sql($SQL)){ print "error1\n"; exit; } $SQL=<<SQL; begin tran select * from xxx commit tran SQL if ($db->Sql($SQL)) { print "error2\n"; exit;} if($db->FetchRow()) { $data=$db->Data(); print "$data\n"; ###when <= 10,467 } else { print "no line\n";###when > 10,467 exit; }
      database is SQLServer,I use Win32::ODBC.
        For my SQL here are the limitations on the size of columns (from the mysql-faq).It is very possible you hit your limit.
        What column (column) types are available with mysql? The following column types are supported: TINYINT A very small integer. Can be a (part of) a key. Signed range -128 +-127. Unsigned range 0-255. Takes 1 byte (8 bits). SMALLINT A small integer. Can be a (part of) a key. Signed range -32768-32 +767. Unsigned range 0-65535. Takes 2 bytes (16 bits). MEDIUMINT A medium integer. Can be a (part of) a key. Signed range -8388608 +-8388607. Unsigned range 0-16777215. Takes 3 bytes (24 bits). INT A normal integer. Can be a (part of) a key. Signed range -21474836 +48-2147483647. Unsigned range 0-4294967295. Takes 4 bytes (32 bits). BIGINT A large integer. Can be a (part of) a key. Signed range -92233720 +36854775808-9223372036854775807. Unsigned Range 0-18446744073709551615. Takes 8 bytes (64 bits). FLOAT A small floating point number. Can be a (part of) a key. Cannot b +e unsigned. Range -3.402823466E+38F - -1.175494351E-38, 0, -1.175494351E-38 - 3.402823466E+38F. Takes 4 bytes (32 bits). DOUBLE A normal floating point number. Can be a (part of) a key. Cannot +be unsigned. Range -1.7976931348623157E+308 - -2.2250738585072014E-308, 0, 2.2250738585072014E-308 - 1.79769313 +48623157E+308. Takes 8 bytes (64 bits). DECIMAL A unpacked floating point number. Can be a (part of) a key. Canno +t be unsigned. Currently the same range maximum range as a double. The number behaves as a CHAR column and takes length+de +cimals bytes. TIMESTAMP A automatic timestamp. Has a range of 1 Dec 1970 kl 0.00 to somet +ime in the year 2106 and a resolution of a second. Can be a (part of) a key. Takes 4 bytes (32 bits). DATE A type to store date information. Uses the "YYYY-MM-DD" syntax, b +ut may be updated with a number or a string. Understand at least the following syntaxes: 'YY-MM-DD', 'YYYY-MM- +DD', 'YYMMDD', 'YYMM', 'YY'. Range 0000-00-00 to 9999-12-31. Takes 4 byte. TIME A type to store time information. Uses the "HH:MM:SS" syntax, but + may be updated with a number or a string. Understand at least the following syntaxes: 'HH:MM:DD, 'HHMMDD', 'HHMM', 'HH'. +Takes 3 bytes. FIXED LENGTH STRING A string that is always filled up with spaces to the specified le +ngth. Can be a (part of) a key. Range 1-255 characters. Takes the same amount of space in the table. VARIABLE LENGTH STRING A string that is stored with its length. Can be a (part of) a key +. Maximum range 1-255 characters. Takes the (varying per row) length + 1 byte in the table. TINYBLOB A binary object that is stored with its length. Can NOT be a key. + Max length 255 characters (8 bits length). Takes the (varying per row) length + 1 byte in the table. BLOB A binary object that is stored with its length. Can NOT be a key. + Max length 16535 characters (16 bits length). Takes the (varying per row) length + 2 bytes in the table. MEDIUMBLOB A binary object that is stored with its length. Can NOT be a key. + Max length 16777216 characters (24 bits length). Takes the (varying per row) length + 3 bytes in the table. LONGBLOB A binary object that is stored with its length. Can NOT be a key. + Range 4294967295 characters (32 bits length). Takes the (varying per row) length + 4 bytes in the table.
Re: FetchRow
by iic (Sexton) on Jul 27, 2000 at 05:53 UTC
    Thank you very much!