0

There is a condition on column written in text:

SomeDecimalColumn = 1234567890 <use your favorite decimal here>

and I need to have a query to a Firebird database to include this condition. Naturally I tried:

//query is a QueryObject of firebird database connection (FbConnection).
// SELECT "A"."SomeDecimalColumn" as C1 
// FROM "MYTABLE" AS "A"
// # SomeDecimalColumn has type DECIMAL(18,0)
var predicate = "SomeDecimalColumn = 1234567890"
query = query.Where(predicate);
//query:
// SELECT "A"."SomeDecimalColumn" as C1 
// FROM "MYTABLE" AS "A" 
// WHERE CAST(1234567890 AS DECIMAL(9,0)) = "A"."SomeDecimalColumn"

It bugs me that it casts string to DECIMAL(9,0) by default. Is there a way to force casting in where to a certain precision, i.e. force DECIMAL(18,0)?

I can't parse this string to separate ColumnName from Value. I don't know a priori what kind of predicate I'm going to get.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Alexandr Crit
  • 111
  • 1
  • 14
  • Try something like this : CultureInfo info = CultureInfo.CurrentCulture; info.NumberFormat.CurrencyDecimalDigits = 5; Convert.ToDecimal("123", info); – jdweng Sep 21 '20 at 17:20
  • @jdweng, does query object reads global culture variable? – Alexandr Crit Sep 22 '20 at 09:36
  • A predicate is a method in this case returns a Boolean. So any code you place in the predicate (including) my code is valid. My code reads the culture. – jdweng Sep 22 '20 at 10:04
  • @jdweng, i'm confused and don't get your message well. Could you elaborate further? My problem is with where clause, that determines type of cast on its own. – Alexandr Crit Sep 22 '20 at 11:22
  • Instead of Cast use Convert.ToDecimal("123", info) – jdweng Sep 22 '20 at 11:58
  • @jdweng, i do not use Cast. I just pass my string expession to where, and it creates a cast clause. To Convert.ToDecimal i have to parse my string expression, and there can be any kind of logical expression written in string. – Alexandr Crit Sep 23 '20 at 06:46
  • The use the code that is commented out. – jdweng Sep 23 '20 at 09:26
  • I'd suggest also asking this question on the [firebird-net-provider Google Group](https://groups.google.com/g/firebird-net-provider) – Mark Rotteveel Sep 24 '20 at 11:29

0 Answers0