Sample Database Application for Programmers New to PureBasic

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
jcaceres
New User
New User
Posts: 5
Joined: Wed Jul 01, 2020 5:49 am

Re: Sample Database Application for Programmers New to PureB

Post by jcaceres »

Hello. nice meeting you. I'm starting to learn the language. I was looking for some postgres sample and found this thread, tried to get purebasicdatabaseapp.zip but the server is not online. Could you please help me to find another resource to get this.
Regards.
infratec
Always Here
Always Here
Posts: 5425
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Sample Database Application for Programmers New to PureB

Post by infratec »

I think this is a good starting point:

Code: Select all

EnableExplicit

Define DB.i, SQL$

UsePostgreSQLDatabase()

DB = OpenDatabase(#PB_Any, "host=localhost dbname=Test port=5432 connect_timeout=5", "User", "Password")
If DB
  Debug "Database open"
  
  SQL$ = "SELECT * FROM test"
  
  If DatabaseQuery(DB, SQL$)
    While NextDatabaseRow(DB)
      Debug GetDatabaseString(DB, 0)
    Wend
    FinishDatabaseQuery(DB)
  Else
    Debug SQL$
    Debug DatabaseError()
  EndIf
  
  SQL$ = "INSERT INTO test (col1, col2) VALUES ('1', '2')"
  If Not DatabaseUpdate(DB, SQL$)
    Debug SQL$
    Debug DatabaseError()
  EndIf
  
  CloseDatabase(DB)
Else
  Debug DatabaseError()
EndIf
For everthing which doesn't return something, you should use DatabaseUpdate()
If something returns something, use DatabaseQuery()
If you use DatabseQuery() don't forget FinishDatabaseQuery()

host can also be an ip address like

Code: Select all

DB = OpenDatabase(#PB_Any, "host=127.0.0.1 dbname=Test port=5432", "User", "Password")
loulou2522
Enthusiast
Enthusiast
Posts: 375
Joined: Tue Oct 14, 2014 12:09 pm

Re: Sample Database Application for Programmers New to PureB

Post by loulou2522 »

I think it will be necessary to show how to install a postgresql server. It's not like sqlite which dosen't need anaything to install.
Thanks to infratec if he shows how to do and param postgresql server
infratec
Always Here
Always Here
Posts: 5425
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Sample Database Application for Programmers New to PureB

Post by infratec »

loulou2522 wrote:I think it will be necessary to show how to install a postgresql server.
That's not PB related :wink:
IdeasVacuum
Always Here
Always Here
Posts: 6380
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Sample Database Application for Programmers New to PureB

Post by IdeasVacuum »

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply