PureBasic Blogging

For everything that's not in any way related to PureBasic. General chat etc...
Phollyer
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Jun 03, 2017 3:36 am
Location: USA, Texas
Contact:

PureBasic Blogging

Post by Phollyer »

For those interested, I have begun writing a blog on PureBasic development, the first series of posts detail the building of an Object-Oriented Database Layer. I am finishing up the Stand-Alone Table, and will be starting on the Parent-Child Table Structures soon.

You can find it directly here:
https://pahlabs.blogspot.com/

or via the Menu of my website:
https://www.PAHLabs.com
dmontaine
User
User
Posts: 50
Joined: Tue Jun 04, 2019 1:03 pm

Re: PureBasic Blogging

Post by dmontaine »

Looked at your DB module. Very interesting. One thing that seems to be missing within Purebasic is the ability to do non-query commands, for example "CREATE DATABASE" or "ALTER TABLE". Do you have any suggestions as to how those operations might be performed from within Purebasic?
Phollyer
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Jun 03, 2017 3:36 am
Location: USA, Texas
Contact:

Re: PureBasic Blogging

Post by Phollyer »

Excellent suggestion! My base DB Module is definitely missing that.
Thank You for your input!

Pete
Phollyer
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Jun 03, 2017 3:36 am
Location: USA, Texas
Contact:

Re: PureBasic Blogging

Post by Phollyer »

I have completed the Blog Posts on the Data-Layer
  • The DB Base Layer
  • Stand-Alone Table
  • Parent-Child Tables
Next Up is Connecting Forms to the Data-Layer
Which will complete this series of entries.
I will Include a link to download all materials, and Examples when is complete.


You can find it directly here:
https://pahlabs.blogspot.com/

or via the Menu of my website:
https://www.PAHLabs.com
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: PureBasic Blogging

Post by Kuron »

Awesome work. PB needs all the tutorials it can get. Many folks (including myself) have not done any database programming in many decades and certainly would not necessarily think to use one for a game. I think part of why so many would NOT think of using a database for game, is so many gaming languages do not have native database support. This is a side of PB I have never explored before, so thank you!

Is it just me, or does Blogspot not offer a RSS feed anymore?
Best wishes to the PB community. Thank you for the memories. ♥️
Phollyer
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Jun 03, 2017 3:36 am
Location: USA, Texas
Contact:

Re: PureBasic Blogging

Post by Phollyer »

Kuron
I have no clue about the RSS feed. I'm still figuring out the Blogging!

Thanks for your kind words about the Blog!

As an Update, there are 6-7 new entries posted today. I've nearly finished this first Tutorial covering from Data-Layer thru View Code or Forms. I'm thinking the next segments will be covering Form Theming and using Custom Controls in your Projects or maybe Animated Sprites on a Windowed Screen? Whichever comes first those will be my next Topics.

You can find it directly here:
https://pahlabs.blogspot.com/

or via the Menu of my website:
https://www.PAHLabs.com
Bitblazer
Enthusiast
Enthusiast
Posts: 761
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: PureBasic Blogging

Post by Bitblazer »

dmontaine wrote: Mon Oct 02, 2023 6:20 pm Looked at your DB module. Very interesting. One thing that seems to be missing within Purebasic is the ability to do non-query commands, for example "CREATE DATABASE" or "ALTER TABLE". Do you have any suggestions as to how those operations might be performed from within Purebasic?
I wondered about the same!

This is what i do during the initialisation of a purebasic software that requires a configuration table to exist:

Code: Select all

Global.i DataBaseHandle

Procedure.i DB_CheckDatabaseUpdate(Query$, Error$ = "not set")
  Define.i Result

  Result = DatabaseUpdate(DataBaseHandle, Query$)
  
  If Result = 0
     Error$ = DatabaseError()
     MessageRequester("Fatal error", "error opening database: " + Error + "(" + Error$ + ")")
  EndIf
   
  ProcedureReturn Result
EndProcedure

Procedure DB_InitConfiguration()
  Define Result.i
  
  Result = DatabaseQuery(DataBaseHandle, "SELECT * from configuration")
  
  If (Result = 0)
    Error$ = DatabaseError()
      
    FinishDatabaseQuery(DataBaseHandle)

    If ((FindString(Error$, "does not exist") <> 0) Or (FindString(Error$, "existiert nicht") <> 0))
      DB_CheckDatabaseUpdate("CREATE TABLE configuration (uid SERIAL PRIMARY KEY, name text, path text, data bytea, wert text)")
    Else
      MessageRequester("Fatal error", "Initialization of the configuration table failed (" + Error$ + ")", #PB_MessageRequester_Ok | #PB_MessageRequester_Error)
      End 666
    EndIf
  Else
    FinishDatabaseQuery(DataBaseHandle)
  EndIf
EndProcedure

Procedure DB_Init()
  
  DataBaseHandle = OpenDatabase(#PB_Any, "host=localhost", #DATABASE_NAME, #DATABASE_PASSWORD)
  
  If (DataBaseHandle = 0)
    Error$ = DatabaseError()
    MessageRequester("Fatal error", "Unable to open postgres database" + Chr(10) + Chr(10) + Error$, #PB_MessageRequester_Ok | #PB_MessageRequester_Error)
    End 666
  EndIf
  
EndProcedure
The software calls db_init() for general database initialisation and afterwards it calls DB_InitConfiguration() to make sure the required table configuration actually exists. If i change the table layout during development, i just change DB_InitConfiguration() with the new values, erase the old table in the database and start the program so it creates the changed table.

ps: be aware that this code only deals with the english and german language to parse error messages. Code like this should never be used in distributed software!
Phollyer
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Jun 03, 2017 3:36 am
Location: USA, Texas
Contact:

Re: PureBasic Blogging

Post by Phollyer »

Agreed. The application design IS TO Distribute the database with the product install,

The solution to my Blog Series is now available to download on my website.

BitBlazer:
I fear you are missing the point of my Series of posts. My goals here are to properly introduce, developers to Object Oriented Development. For this series of posts to include every possible condition would make it too difficult, AND way TOO LONG, for most to follow along. I am attempting to bring folks into "A" way of thinking about Programming, "A" way of Developing software, which to many would not an obvious way of writing code. To keep this LONG Series of posts focused on what "I" consider to be on topic and Not TOO Much to handle I have left out a lot. These are all things that can be dealt with after we have them on board, and thinking correctly about coding.

BitBlazer, Might I recommend you take up a Blog and introduce folks into your step-by-step approach to software development. In fact you can pick up where I left off and add your own methodology for folks to consider.

  --------------------------

So for those of you who have followed along with the Blog Series, I have posted the Complete Solution on my website ready for downloading.

Blog Series is here:
https://pahlabs.blogspot.com/

Website is Here:
https://www.PAHLabs.com
Post Reply