LDB ( Little DataBase ) 1.0 Beta

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

There is a simple way to do what you want ( without modify th lib )
Just read a data with read(field)

and search what you want

1° Example ">"

Code: Select all

a=Val(LdbRead(1))
Value=10
if a > Value --> Do what you want
2° Example "Starts"

Code: Select all

B.s=LdbRead(2)
Start.s="BEGIN"
if len(B)>=Start and if Left(B,len(Start))=Start --> Do what you want
3° Example "Ends"

Code: Select all

C.s=LdbRead(2)
Ends.s="END"
if len(C)>=Ends and if Right(C,len(Ends))=Ends --> Do what you want
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Thanks Droopy

Post by Fangbeast »

I now have a simple diabetic diary program using your linked list database system that fits easily on a floppy disk with the data file.

Only think I'd ask you to do is find another delimiter character to store the records as CR/LF pairs are not robust enough. An example is when you use the editorgadget to enter notes into and press ENTER to start a new line in it, this will now be truncated by the library routines. I usually use the "|" character in text databases because it would be highly unlikely that anyone would type that normally.

I can't recompile the lib as I don't have (or know how to use) tailbite.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

For compile the Lib with Tailbite it's very easy

1° Launch Tailbite
2° In Select Source File : select my source file
3° Click Tailbite ! it

There is no problem with CR/LF delemiter
Because when you use LDBWrite the function replace all pairs #CRLF by a Chr(1)

And when you use LDBRead all Chr(1) is replaced by a #CRLF

This is an example to show this

Code: Select all

LdbInit()
LdbCreate("d:\test.txt","Name")
LdbInsertRecord(-1)
TextWithCRLF.s="First line"+#CRLF$+"Second line"+#CRLF$+"Third line"
LdbWrite(1,TextWithCRLF)
MessageRequester("Multiline Read",LdbRead(1))
LdbSaveDatabase()
LdbCloseDatabase()
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

I wish I could agree but...

Post by Fangbeast »

I already tested this and it did truncate it at the first CR/LF it found in the text.

Try it.

Create an editorgadget, write some text into it, press ENTER to create a new line and write some more. Save the database, exit the program, re-start the program, reload the database.

The text is missing after the AFTER where you pressed the ENTER originally.

Just trying to help, not a criticism:):):):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

For me there is no bug

Here's 2 new code for testing

1° Write a Multiline ( EditorGadget to Database )

Code: Select all

OpenWindow(0,0,0,322,150,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0)) 
EditorGadget (0,8,8,306,133,#PB_Container_Raised) 
    
LdbInit() 
LdbCreate("d:\test.txt","Name") 

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow 

LdbInsertRecord(-1) 
LdbWrite(1,GetGadgetText(0)) 
LdbSaveDatabase() 
LdbCloseDatabase() 
2° Read the Database ( EditorGadget from Database )

Code: Select all

OpenWindow(0,0,0,322,150,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0)) 
EditorGadget (0,8,8,306,133,#PB_Container_Raised) 
    
LdbInit() 
LdbOpen("d:\test.txt") 
LdbSetPointer(1)
SetGadgetText(0,LdbRead(1))
LdbSaveDatabase() 
LdbCloseDatabase() 

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow 
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Okay, found the problem.

Post by Fangbeast »

The CR/LF's are definately the problem.

I was putting in:

SendMessage_(GadgetID(0), #EM_SETTARGETDEVICE, #NULL, 0)

To set wordwrap on in the EditorGadget because without it, it is useless to read long text. I created two records and only the second would be read back in and displayed. There is an extra char being inserted or interpreted somewhere and I can't find it.

Code: Select all

OpenWindow(0,0,0,322,150,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0))
EditorGadget (0,8,8,306,133,#PB_Container_Raised)
SendMessage_(GadgetID(0), #EM_SETTARGETDEVICE, #NULL, 0)  ; Set wordwrap in comment
   
LdbInit()
LdbCreate("C:\test.txt","Name")

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

LdbInsertRecord(-1)
LdbWrite(1,GetGadgetText(0))

Delay(5000) ; Small delay before duplicating this record.

LdbInsertRecord(-1)
LdbWrite(1,GetGadgetText(0))

LdbSaveDatabase()
LdbCloseDatabase() 

Code: Select all

OpenWindow(0,0,0,322,150,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0))
EditorGadget (0,8,8,306,133,#PB_Container_Raised)
SendMessage_(GadgetID(0), #EM_SETTARGETDEVICE, #NULL, 0)  ; Set wordwrap in comment
   
LdbInit()
LdbOpen("d:\test.txt")

LdbSetPointer(1)
SetGadgetText(0, "1 - " + LdbRead(1))

Delay (5000)

ClearGadgetItemList(0)

LdbSetPointer(2)
SetGadgetText(0, "2 - " + LdbRead(1))

LdbSaveDatabase()
LdbCloseDatabase()

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow 
I might have to disassemble the text file with a hex editor too see if there is an embedded, hidden char somewhere.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

I think your problem is in your code
You don't use the same database !
( 1st = C:\test.txt 2nd=D:\test.txt)

I don't know why you use the delay(5000)
and don't understand why you use the sendmessage_ function

I modify your code


Code: Select all

OpenWindow(0,0,0,322,150,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0)) 
EditorGadget (0,8,8,306,133,#PB_Container_Raised) 
    
LdbInit() 
LdbCreate("D:\test.txt","Name") 

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow 

LdbInsertRecord(-1) 
LdbWrite(1,GetGadgetText(0)) 

LdbInsertRecord(-1) 
LdbWrite(1,GetGadgetText(0)) 

LdbSaveDatabase() 
LdbCloseDatabase() 
and the second

Code: Select all

LdbInit() 
LdbOpen("d:\test.txt") 

LdbSetPointer(1) 
MessageRequester("Record N° 1",LdbRead(1))

LdbSetPointer(2) 
MessageRequester("Record N° 2",LdbRead(1))

LdbCloseDatabase() 
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Sorry about the mistake.

Post by Fangbeast »

I just edited the code on the run as i've been in and out all week.

The test was still valid for the original code after I remembered to change the drive letters however so I will play with this and have a look.

As for SendMessage, I am turning on WordWrap in the editor gadget (my comment in my original code above said this already) and this is where the problem occurs. It seems that the process of 'wrapping' in the editor gadget adds an extra soft/hard (don't know which) CR or LF somewhere which is why the text is being truncated.

My comment about using another character pair instead of CRLF still stands because people will want to use the editor gadget and WRAP their text to make it more readable and this will cause a problem with the text being truncated.

I always use the "|" character in text databases as it's higly unlikely that anyone except programmers will use that in text. But, that's just my exeperience.

I'll try to learn about tailbite and modify your library to use the different delimiter to solve my own problem.

Will play tonight (never enough time)

Thanks for a great library and the hard work you put into this.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

Great lib!

is there a chance you can do the same commands for MDB files of access?
this will be an easy wrapper for that, there is Paul's MDB lib but it doesnt extend in much commands such as search and stuff

and i am lousy in queary messages to the OBDC so if this lib same functions could work on MDB access files , it will be great and easy to use!


please consider :)

thank you.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

I don't think

I'll have to learn ODBC too
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Pantcho!! wrote:there is Paul's MDB lib but it doesnt extend in much commands such as search and stuff

LOL @ Pancho... your comment is nonsense.
The MDB_Lib creates a quick ODBC connection to your MDB (Access) database. After that you have the entire SQL language for performing whatever action you need, and you will not find more powerful search/query commands than those in the SQL language!
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

:lol: Paul i just looooooove your libs and you know it!
but what i meant is that your MDB lib is great but OBDC is strange for me
and there are so lack of examples (In PB) of SQL commands so i can understand how SQL works in PB. your lib does save ALLOT with connecting the OBDC (hell i dont know what even OBDC stands for..) even trough SQL connect and thats great! but the quaries in order to SORT/SEARCH/ADD/DELETE are not familier to me and in Droopy LDB it is, so it will be great if someone could do a PB with OBDC common Quaries.


thanks!
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Pantcho!! wrote:and there are so lack of examples (In PB) of SQL commands so i can understand how SQL works in PB.
That's like saying I want to use PHP with some web stuff I'm writing in PureBasic so PureBasic should have a bunch of tutorials to show me how ;)

SQL (like PHP or ASM or even WinAPI) is a completely different language so you must search the appropriate sites for the information you require.
PureBasic provides the interface to the language with the command DatabaseQuery() ... you must provide the appropriate syntax.

If you don't feel like Googling "sql syntax" then just look at the "Sample.pb" file in the "Demo Files\MDBLib Demo" folder.
The example shows you how to create and connect to your MDB database, it shows how to create tables in the database, it shows how to put data into the tables, and then it shows how to search and retrieve data from the tables.
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

Paul thank you very much! :) and i am sorry if it looked like i am lazy i am not , you can be sure of that.
meny thanks for the info.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Tutorials

Post by Fangbeast »

And while we are on the subject, there are so many mentions of SQL in the forum, pointers to tips, pointers to tutorials, pointers to example code etc. That's how I got started.

Go to www.purearea.net and look for the tutorials and download them. Code examples in there too.Download the codearchive and there should be examples in there.

Got to the following for sql syntax, help, sample code in many languages.

sqlzoo.net
www.w3schools.com
www.1keydata.com
www.sql.org
www.sqlite.org
www.keithjbrown.co.u

And the last

www.mysql.com

This one has an online sql manual or a downloadable somewhere ont he site (around 4 meg) that is full of SQL syntax that is very usable on many varieties of sql variants.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply