Gabriel C. Ullmann
Gabriel C. Ullmann

Reputation: 151

How to execute query longer than 32767 characters on Firebird?

I'm developing a Java web application that deals with large amounts of text (HTML code strings encoded using base64), which I need to save in my database. I'm using Firebird 2.0, and every time I try to insert a new record with strings longer than 32767 characters, I receive the following error: GDS Exception. 335544726. Error reading data from the connection.

I have done some research about it, and apparently this is the character limit for Firebird, both for query strings and records in the database. I have tried a couple of things, like splitting the string in the query and then concatenating the parts, but it didn't work. Does anyone know any workarounds for this issue?

Upvotes: 2

Views: 2620

Answers (2)

Mark Rotteveel
Mark Rotteveel

Reputation: 109001

Firebird query strings are limited to 64 kilobytes in Firebird 2.5 and earlier. The maximum length of a varchar field is 32766 byte (which means it can only store 8191 characters when using UTF-8!). The maximum size of a row (with blobs counting for 8 bytes) is 64 kilobytes as well.

If you want to store values longer than 32 kilobytes, you need to use a BLOB SUB_TYPE TEXT, and you need to use a prepared statement to set the value.

Upvotes: 2

Maxim Votyakov
Maxim Votyakov

Reputation: 724

If you need to save large amount of text data in the database - just use BLOB fields. Varchar field size is limited to 32Kb. For better performance you can use binary BLOBs and save there zipped data.

Upvotes: 4

Related Questions