varchar(max) length

107 views
Skip to first unread message

Davi Ruiz

unread,
Nov 4, 2009, 2:22:59 PM11/4/09
to Rails SQLServer Adapter
Hello,

I'm trying to get some values from table below:

create_table :pages do |pages_table|
pages_table.with_options :null => false do |t|
t.belongs_to :rule
t.integer :parent_id, :page_template_id, :editor_id, :null =>
true
t.string :status, :limit => 32, :default => 'new'
t.string :path, :limit => 255
t.string :title, :limit => 255, :null => true

t.text :content, :summary, :meta_description, :meta_keywords, :null
=> true
t.datetime :created_at, :updated_at
t.datetime :active_at, :expires_at, :deleted_at, :null => true
end
end

When I get content value, it's 4096 characters, but the field in DB is
6000 characters.

Do you have any idea about this?

I'm using Debian and rails 2.3.4.

Ken Collins

unread,
Nov 4, 2009, 3:38:09 PM11/4/09
to rails-sqlse...@googlegroups.com

Hi Davi,

Welcome to the group. It may help to see all the column objects that
the migration created. For instance, can you post all of what
Page.columns returns from the console? Also, can you explain what you
mean by "get content value, it's 4096 characters"? Does that mean you
have a value stored in the column that is that long? If so, that is
not an issue, the underlying schema SQL type should be a varchar(max)
for that migraiton on SQL Server 2005/2008 and hence, means you can
store any length in that field. I'm sure I can help, just need to
understand the problem a bit more.


- Cheers,
Ken

Ken Collins

unread,
Nov 4, 2009, 8:42:42 PM11/4/09
to rails-sqlse...@googlegroups.com

Also, I'm just shooting in the dark here, have you read the section
titled "Native Text/String/Binary Data Type Accessor" in the readme?
Does that filter into this discussion at all?

http://github.com/rails-sqlserver/2000-2005-adapter


- Ken

Davi Ruiz

unread,
Nov 5, 2009, 6:55:44 AM11/5/09
to Rails SQLServer Adapter
Yes Ken, I read this section. My DB is SQL 2005

I tried all the following settings:

ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type
= 'varchar(8000)'
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type
= 'varchar(max)'
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type
= 'text'

this not worked for me...

The output from console is here:

http://pastie.org/684628

"Also, can you explain what you
mean by "get content value, it's 4096 characters"? Does that mean
you
have a value stored in the column that is that long?"

Yes, I have 6000 characters stored in the column "content", however
when I start the application, I got just 4096.

In the Windows environment works well... but my server is Debian

Ken Collins

unread,
Nov 5, 2009, 8:35:29 AM11/5/09
to rails-sqlse...@googlegroups.com

FYI, those settings only apply for migrations when new columns are
created.

Also, I'm going to need to see more examples of where you not seeing
results. For instance, here I am in the console of my test app hooked
up to the same classes used under the ActiveRecord/SqlserverAdapter
test suite. Can you correlate your examples like this?

http://pastie.org/684730

So far I am seeing exactly what I should be seeing. FYI, this console
is in ruby 1.8.7/unixODBC/SS2005. I get the same results under 1.9.x
too and so far can not reproduce your issue at the moment, if I am
understanding it correctly?


- Ken

Davi Ruiz

unread,
Nov 5, 2009, 12:09:19 PM11/5/09
to Rails SQLServer Adapter
yes I know that... this migration is new too...

this example is the same that yours:

http://pastie.org/685072

What's your environment?

I'm using Debian ruby 1.8.7 rails 2.3.4 ruby-odbc 0.9997 and unixodbc-
dev 2.2.11-16

I did some tests with fedora 10 and ubuntu in a virtual machine and I
had the same results...

Davi Ruiz

unread,
Nov 6, 2009, 8:06:59 AM11/6/09
to Rails SQLServer Adapter
I got a solution...

If I use Page.find_by_sql("set textsize 25000 select * from pages") it
works well.

I don't know if it's some setting in unixodbc. I believe it is a
temporary solution.

Ken Collins

unread,
Nov 6, 2009, 8:39:34 PM11/6/09
to rails-sqlse...@googlegroups.com

Davi,

Sorry for the slow response, had a big event here in 757 yesterday. I
just looked at this again and I can not reproduce your issue. I would
really start debugging deep on your end. Thinks like setting in your
ODBC layer that is truncating strings, perhaps code in your model that
is doing something, a server side configuration that is truncating
returned rows via network connections, something. What you really
should do is run the tests and see how far this goes.

Question... from this pastie <http://pastie.org/685072>, what would
happen if you did this:

Page.last.content_before_type_cast
Reply all
Reply to author
Forward
0 new messages