I am working on a database program using dbExpress components (Delphi 7). Data is extracted from the database through the following components: TSQLDataSet → TDataSetProvider → TClientDataSet → TDatasource → TDBEdit. So far, the form has worked correctly. Query in TSQLDataset
select id, name, byteken, timeflag from scales where id = :p1
I added a large (2048) varchar field to the database table; when I add this field to the above request (and connect TDBMemo or TDBRichEdit) to TDatasource), I get the following message when I try to change the value in a new text field
Unable to find record. No key specified.
I get the same error when there is no TDBMemo on the form (but with the varchar field in the request). As soon as I remove the varchar field from the request, everything works correctly again.
What could be causing this problem?
==== Additional information ====
Now I have defined the constant fields in the form. The field that contains the key to the table has the provider flags set to [pfInUpdate, pfInWhere, pfInKey], while all other fields have their flags like [pfInUpdate, pfInWhere]. This does not solve the problem.
Permanent fields have been defined on clientdataset. When I defined them in TSQLDataSet, the error message "no key specified" does not occur. The program still issues this error message (which I forgot to mention earlier):
EDatabase error: arithmetic exception, numeric overflow or string truncation
The large row field has the correct value in 'displaywidth' and 'size'.
==== Even more information ====
I rewrote the form to use non-data components. One query retrieves data from the database (using exactly the same query string as I use in TSQLDataSet); data is then transferred to the controls. After the user clicks the OK button on the form, the data is transferred back to the database through another request that performs an update or insert. Since this works correctly, I do not see that the problem is with data-aware components.
==== Another piece of information ====
I found this stack overflow question that seems to address a similar issue. I changed the request as
select id, name, name, byteken, timeflag, cast (constext as varchar (2048)) as fconstext from scales where id = :p1
and set the dbMemo data field as "fconstext". After adding text to dbMemo, the call to "applyupdates" now fails with the following message
column unknown 'fconstext'
despite the fact that there is a constant field created with this name.
I do not know if this helps or just stirs up the water.
==== Additional information, April 23 ====
I deleted the field from the database table and then added it back. A program written in writing works fine as long as the line entered in the problem data field is less than 260 characters. I added ten characters at a time several times without problems until the line length was 256. Then I added a few more characters (without counting), tried to save - and got an error. From now on, trying to add another character , an error message appears (which comes in the "applyupdates" clientdataset method).
Initially, the field contained 832 characters, so there is no hard limit on the number of characters that I can successfully save. But as soon as an error message appears, it always appears as if the database remembered that there was an error.
==== Additional information, April 24 ====
Once again, I deleted the field from the database and added it back; the character set is WIN1251, for reasons that I don’t understand (I don’t need Cyrillic characters). The maximum number of characters that I can enter using data controls seems to be around 280, regardless of how this field is defined.
Since then, I switched to using non-data controls in a real program where this problem occurs, and I can assure you that this restriction does not exist there. Thus, I am sure that the problem is not due to the mismatch of character size, as suggested. Do not forget that I am using Delphi 7, which does not have unicode strings. I think that there is an error in one of the components, but since I am using older versions, I think that the problem has been resolved, but not in the versions that I am using.
==== Hope final editing, 25/04/12 ====
Following the advice of mosquitoes, I created a new database whose default character set is WIN1252 (UTF-8 was not selected as a choice, and, in any case, my programs are not unicode). In this clean database, I defined one table where the character set of the string "constext" was also defined as WIN1252. I launched a data-oriented version of the problematic form, and was able to enter text without any problems (currently over 1700 characters).
Thus, it would seem that the problem was created using one character set defined for the database and one for the field. I do not know how to check in retrospect which default character set for the database has been defined, so I cannot confirm this.
Now I have a little problem with defining a new database (there are 50+ tables) and copying data from the original database. Since this database serves the product of the flagship client, I am somewhat wary of this ....