I am trying to validate an integer field called quantity. I don''t know
how to chack if it has gone beyond or below the maximum or minimum value
allowed by the Firebird RDBMS. I tired adding this code to the validate
method in the model:
if (quantity > -2147483648) and (quantity < 2147483648)
errors.add("quantity", "is out of range (must be between
-2147483648 and 2147483648)")
end
But when I try entering a big value for example a bunch of numbers in
the form field I get this sql error when I hit edit:
FireRuby::FireRubyException: Error preparing a SQL statement.
Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, char 239
9
Invalid token
SQL Code = -104
Firebird Code = 335544569
: UPDATE parts SET "ORDERED_DATE" = CAST(''2006-05-24
21:45:00'' AS
TIMESTAMP), "ORDER_ID" = 13, "END_DATE" = NULL,
"PROVIDER_ID" = 2,
"CODE" = ''jojo '',
"GOAL_DATE" = CAST(''2006-05-28
21:45:00'' AS TIMESTAMP), "QUANTITY" =
99999999999999999999999999999999999999999999888888888888888888888888888888886666666666666666666666
WHERE id = 2
Any suggestions on the best way to validate an integer field?
Best regards.
--
Posted via http://www.ruby-forum.com/.
On 5/25/06, Juan Tarquino <jptarqu@yahoo.com> wrote:> I am trying to validate an integer field called quantity. I don''t know > how to chack if it has gone beyond or below the maximum or minimum value > allowed by the Firebird RDBMS. I tired adding this code to the validate > method in the model: > > if (quantity > -2147483648) and (quantity < 2147483648) > > errors.add("quantity", "is out of range (must be between > -2147483648 and 2147483648)") > > endThat logic looks backwards. unless (quantity > -2147483648 && quantity < 2147483648) ... end
In your model class: validates_inclusion_of :quantity, :in => -2147483648..2147483648 Cheers! -DF On 5/26/06, Juan Tarquino <jptarqu@yahoo.com> wrote:> I am trying to validate an integer field called quantity. I don''t know > how to chack if it has gone beyond or below the maximum or minimum value > allowed by the Firebird RDBMS. I tired adding this code to the validate > method in the model: > > if (quantity > -2147483648) and (quantity < 2147483648) > > errors.add("quantity", "is out of range (must be between > -2147483648 and 2147483648)") > > end > > But when I try entering a big value for example a bunch of numbers in > the form field I get this sql error when I hit edit: > > FireRuby::FireRubyException: Error preparing a SQL statement. > Dynamic SQL Error > SQL error code = -104 > Token unknown - line 1, char 239 > 9 > Invalid token > SQL Code = -104 > Firebird Code = 335544569 > : UPDATE parts SET "ORDERED_DATE" = CAST(''2006-05-24 21:45:00'' AS > TIMESTAMP), "ORDER_ID" = 13, "END_DATE" = NULL, "PROVIDER_ID" = 2, > "CODE" = ''jojo '', "GOAL_DATE" = CAST(''2006-05-28 > 21:45:00'' AS TIMESTAMP), "QUANTITY" > 99999999999999999999999999999999999999999999888888888888888888888888888888886666666666666666666666 > WHERE id = 2 > > Any suggestions on the best way to validate an integer field? > > Best regards. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >