Forum > Databases
DBMemo truncates string
artem101:
Hello all!
I use SQLite3 database. My table has field defined with VARCHAR type (without length specified). I have TDBMemo to edit it.
I see weird things:
* After saving to database string truncates to TField.Size x 4 characters.
* I tried to increase TField.Size - when I set big value (for example about 1000), my application crashes with SIGSEGV error.
MaxLength property of DBMemo = 0.
Could somebody explain me how Size property works and how to increase max length (or make it unlimited) for DBMemo?
I have:
* Lazarus 2.0.12
* FPC 3.2.0
* Windows 7 64bit
* SQLite3 dll 3.37.2
Thanks.
Sieben:
If you want that field to be unlimited in size, change type to TEXT in your database and make sure that it is a TMemoField in your application by deleting and recreating the associated FieldDef and TField (which presumably is a TStringField right now).
artem101:
Is any difference between VARCHAR and TEXT? In SQLite3 they are synonyms, aren't they?
I add changes you advised, but now have error "dataset is not in edit or insert state".
Also in DBGrid value of this field looks as (MEMO).
Can you have a look at my code?
Sieben:
--- Quote from: artem101 ---Is any difference between VARCHAR and TEXT? In SQLite3 they are synonyms, aren't they?
--- End quote ---
As far as the database's internal storing and processing is concerned, yes. But a field reported as VARCHAR by schema info is 'translated' to a TStringField, while TEXT results in a TMemoField.
--- Quote ---I add changes you advised, but now have error "dataset is not in edit or insert state".
--- End quote ---
That's another issue unrelated to the field type. Is AutoEdit of the corresponding DataSource set to True?
--- Quote ---Also in DBGrid value of this field looks as (MEMO).
--- End quote ---
That's the standard display text of a TMemoField. You can use the TField's OnGetText event to supply the real content or, better, just a sufficient part of it. Like this for instance:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const cGridMemoLength = 75;//...procedure TdmMain.MemosGetGridText(Sender: TField; var aText: string; DisplayText: Boolean);begin if DisplayText then begin aText := Sender.AsString; SetLength(aText,cGridMemoLength); aText := ReplaceStr(aText,LineEnding,' '); aText := aText + '...'; end;end;
Will have a look at your code as well - EDIT: but can't get it to run due to a 'malformed database schema' error.
Zvoni:
--- Quote from: artem101 on April 08, 2022, 10:04:25 pm ---Also in DBGrid value of this field looks as (MEMO).
--- End quote ---
There is an option in Object-Inspector of DBGrid, to show Memo-Text correctly, or cast the Field to Char in your Select-Statement
Navigation
[0] Message Index
[#] Next page