I work in C # with the Firebird base. There is a table with a field of type varchar, the encoding Win1251 and the length set to 2000. If you change it in this field, some records give an error

firebird arithmetic exception, numeric overflow, or string truncation

string right truncation

I do not understand what the problem is.

PS That's what I noticed. If the total length in the field is more than 1036 characters, then when a change request is received, this error occurs.

The code itself:

using (FbConnection con = new FbConnection(ConString)) { con.Open(); string sql = "UPDATE OR INSERT INTO 'PARTS' ('ID','PART','DATAOTGR','CONTRACT','MBRUTTO','MNETTO','EXPORTED','PAKETS') \n" + "VALUES ( @id , @part ,@dataotgr, @contract ,@mbrutto,@mnetto,@exported,@pakets) \n" + "matching (id);"; FbCommand InsertSQL = new FbCommand(sql, con); FbParameter param; //создаСм ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ param = new FbParameter(" @ID ", obj.id.ToString()); //добавляСм значСния ΠΈ имя InsertSQL.Parameters.Add(param); //Ρ‚Π΅ΠΏΠ΅Ρ€ΡŒ добавляСм ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ ΠΊ ΠΊΠΎΠΌΠΌΠ°Π½Π΄Π΅ param = new FbParameter(" @PART ", obj.part1); //ΠΈ дальшС Ρ‚Π°ΠΊ ΠΆΠ΅ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΈ мСняСм Ρ‡Ρ‚ΠΎ значСния InsertSQL.Parameters.Add(param); param = new FbParameter("@dataotgr", obj.dataOtgr); param.FbDbType = FbDbType.Date; InsertSQL.Parameters.Add(param); param = new FbParameter(" @contract ", obj.contract); InsertSQL.Parameters.Add(param); param = new FbParameter("@MBRUTTO", obj.mBrutto); InsertSQL.Parameters.Add(param); param = new FbParameter("@MNETTO", obj.mNetto); InsertSQL.Parameters.Add(param); //Π½Π΅ соотвСтствиС Ρ‚ΠΈΠΏΠΎΠ² ΠΈ Π±Π»Π°-Π±Π»Π°-Π±Π»Π°. ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΠ΅ΠΌ bool Π² string, Π² самой Π±Π°Π·Π΅ CHAR(1) string exp = obj.exported ? "1" : "0"; param = new FbParameter("@exported", exp); InsertSQL.Parameters.Add(param); param = new FbParameter("@pakets", obj.pakets); //АГА! Π²ΠΎΡ‚ ΠΎΠ½ΠΎ ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΠ½ΠΎΠ΅ ΠΏΠΎΠ»Π΅. ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ Π΄Π»ΠΈΠ½Π° строки obj.pakets Π±ΠΎΠ»Π΅Π΅ 1000 символов. InsertSQL.Parameters.Add(param); FbTransaction fbt = con.BeginTransaction(); //стартуСм Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΡŽ InsertSQL.Transaction = fbt; // проинициализация Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ для ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° InsertSQL int res = InsertSQL.ExecuteNonQuery(); //Π½ΡƒΡƒ ... сам запрос отправляСм fbt.Commit(); //Ссли вставка ΠΏΡ€ΠΎΡˆΠ»Π° ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ - ΠΊΠΎΠΌΠΈΡ‚ΠΈΠΌ Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΡŽ con.Close(); //Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ соСдинСниС } 
  • Maybe you should look at the options about the limitations? - BuilderC
  • @BuilderC, did not quite understand. If you're talking about the length of the column, then I tried and put 6000. All the same, the same trouble - zerpico

2 answers 2

In Firebird 2.5, VARCHAR (n) allows you to store up to 32KB.

For a more accurate answer, please provide a sample code.

Update

I would write one instead of 2 lines:

 InsertSQL.Parameters.AddWithValue("@pakets", obj.pakets); 
  • source of what? I just make a request for Update entries and I get this error. - zerpico

1 character win1251 occupies one byte, 1 character unicode occupies one or more bytes (the specific amount depends on the character and encoding used). VARCHAR (2000) can store not two thousand characters, but two thousand bytes.