php - Why does SQL Server select query truncate varchar string? -
setup
i using several memory tables cache data website. local web host on mac , dev server on linux using mssql php library on php 5.5
a simplified table looks like:
cacheid int not null cachedata varchar(max)
i insert several large values. 10,000+ characters. insert works fine. simple query tells me data in field:
select cacheid, len(cachedata) caches
problem
however, when select data cache
column truncated 8192 characters causing problems. simple select:
select cachedata caches cacheid = 10
i checked varchar(max) character limit. , beyond 8192. 2^32 - 1
the question
why data being truncated?
the question in form. ran agian , forgot solution. took me bit remember forgot root cause. here searched thinking sql server culprit.
what sql servers varchar(max) maximum length? - if values being truncated caused php non sql server. if want know max is, question answered here: maximum size of varchar(max) variable
disclosure
answering own question. posting here because took me on hour hunt issue down , nice have strait-forward answer it. i've seen similar questions on stack overflow specific use case or poorly worded not findable search results
answer
mssql module php has several default settings in php.ini file. 1 of settings mssql.textlimit
, mssql.textsize
. these settings truncate text based field (varchar, text, nvarchar) size set too.
i have seen posts truncate on 8192 , 4096. assume either of these can default. upped mine 65535 (2^16 - 1).
other related issues
as side note have seen similar question query results in sql server management studio. there several limitations in program how many characters can displayed or exported. there settings in program edit number of characters displayed/exported. more info on issue here.
Comments
Post a Comment