Active Record Select Truncating Text |
[eluser]atomicx6637[/eluser]
I have a text field in a MSSQL database that is a varchar(5000). When the user inserts the data using activerecord via the webpage it inserts the data just fine, but when I'm querying the database the field data is getting truncated to about 253 chars. I run the query in Microsoft Studio and I see all the data. Any ideas? Thanks Troy
[eluser]DynamiteN[/eluser]
could be that im just remembering wrong but i think varchar only allow up to 255 ? tried to use text instead that would be able to hold up to 5000 :/ ... GL
[eluser]flaky[/eluser]
@DynamiteN In MSSQL varchar can go up to 8000, but if you want more you can use MAX value. In MySQL you can use bigger values than 255 but depending on the value it will be converted to TEXT, MEDIUMTEXT etc. Quote:The maximum storage size for VARCHAR(MAX) is 2^31-1 bytes (2,147,483,647 bytes or 2GB - 1 bytes). The storage size is the actual length of data entered + 2 bytes. The data entered can be 0 characters in length. Since each character in a VARCHAR data type uses one byte, the maximum length for a VARCHAR(MAX) data type is 2,147,483,645.
[eluser]atomicx6637[/eluser]
The storing of the varchar(5000) isn't a problem it is when I try to retrieve it from the database it is only bringing back 253 characters even through there is 600+ chars in the db.
[eluser]atomicx6637[/eluser]
Code: function loadById($applicationId)
[eluser]atomicx6637[/eluser]
I changed the type in the database from varchar(4000) to text and it is working now. I ran across this in the mssql_query docs. http://php.net/manual/en/function.mssql-query.php Quote:NOTE that the DB library that is internally driving these functions will NOT return more than 256 characters for data types varchar are char. After SQL Server 7 they allowed for lengths of up to 8000, but never updated the library. This drove me crazy for a day (all other connectivity worked from Java and C#, just not PHP). So, switch your data type to text if you wish to have lengths more than 256 characters.
[eluser]becky.resler[/eluser]
I just ran across this issue myself. I'm glad I found this thread so I didn't end up ripping all my hair out. I just wanted to mention, you don't have to change the data type on the columns. You can cast the column as text when doing a select and the data won't get cut off. For example, if I have a table structured as such: Code: CREATE TABLE dbo.mytable I can cast the description column and not lose any data. Code: $this->db->select("id, title, CAST(description AS text) AS description", true)->from("mytable"); I did this in my current project and it worked like a charm. |
Welcome Guest, Not a member yet? Register Sign In |