How to save CRLF in editorgadget to database and back?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

How to save CRLF in editorgadget to database and back?

Post by Fangbeast »

I can't remember how I did this years ago but when I type some text into an editorgadget and save the text to a database, bringing it back comes back truncated and messed up.

How do you handle this?

I tried some RTF routines thinking it would solve the problem but it didn't
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Re: How to save CRLF in editorgadget to database and back?

Post by walker »

Hi,

i'd solved this by parsing the text and replacing the CRLF by another character that never will occur and has no meaning to the database. Chr(7) is such a char
Or replace the CRLF by the HTML equivalent "<br>"

If you read the database, reverse your search :D
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: How to save CRLF in editorgadget to database and back?

Post by Fangbeast »

walker wrote:Hi,

i'd solved this by parsing the text and replacing the CRLF by another character that never will occur and has no meaning to the database. Chr(7) is such a char
Or replace the CRLF by the HTML equivalent "<br>"

If you read the database, reverse your search :D
Thanks for that. I still have trouble remembering things I lost years ago
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: How to save CRLF in editorgadget to database and back?

Post by falsam »

Try this code: When the code is run, copy this code in the editor, save and load.

Code: Select all

Enumeration database
  #database
EndEnumeration

Enumeration window
  #mainform
EndEnumeration

Enumeration gadget
  #editor
  #save
  #load  
EndEnumeration

Procedure.s DoubleSpec(String.s)
  Protected Buffer.s
  Buffer = ReplaceString(String, "'", "''")
  ProcedureReturn Buffer
EndProcedure

Procedure databasesave()  
  Protected buffer.S = DoubleSpec(GetGadgetText(#editor))
 
  DatabaseUpdate(#database, "insert into MyTable (editor) values('" + buffer+ "')")
  Debug DatabaseError()
  SetGadgetText(#editor, "")
EndProcedure

Procedure databaseload()
  DatabaseQuery(#database, "SELECT editor FROM MyTable")
  NextDatabaseRow(#database)
  SetGadgetText(#editor, GetDatabaseString(#database, 0))
EndProcedure

UseSQLiteDatabase()
OpenDatabase(#database, ":memory:", "", "")
DatabaseUpdate(#database, "CREATE TABLE MyTable (editor TEXT);")       

OpenWindow(#mainform, 0, 0, 800, 600, "Save Editor to Database")
EditorGadget(#editor, 5, 5, 700, 595)
ButtonGadget(#save, 710, 5, 80, 22, "Save")
ButtonGadget(#load, 710, 30, 80, 22, "Load")
SetActiveGadget(#Editor)

BindGadgetEvent(#save, @databasesave())
BindGadgetEvent(#load, @databaseload())

Repeat : Until WaitWindowEvent(10) = #PB_Event_CloseWindow  

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: How to save CRLF in editorgadget to database and back?

Post by Fangbeast »

I have no trouble with database in general falsam, just forgot how to deal with pesky crlf's. I'm getting OLDer!! :):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: How to save CRLF in editorgadget to database and back?

Post by Olliv »

Fangbeast

replacing effective new line characters with this RTF string:

Code: Select all

"\par "
?
Olli
Addict
Addict
Posts: 1232
Joined: Wed May 27, 2020 12:26 pm

Re: How to save CRLF in editorgadget to database and back?

Post by Olli »

Hey fangbeast ! It was a question ! :mrgreen:

/par means paragraph so it does a carriage return...

I apologize to have been late (2 months) to answer : in Juny, 2014 I had an car accident...



I am searching where I published a highlight test in a EditorGadget...
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: How to save CRLF in editorgadget to database and back?

Post by Fangbeast »

2 months?? Don't you mean 7 years?????

Stop having accidents, come over here and help me move:):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply