Page 2 of 2

Re: Sample Database Application for Programmers New to PureB

Posted: Wed Jul 01, 2020 6:40 am
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.

Re: Sample Database Application for Programmers New to PureB

Posted: Wed Jul 01, 2020 7:50 am
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")

Re: Sample Database Application for Programmers New to PureB

Posted: Thu Jul 02, 2020 9:01 am
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

Re: Sample Database Application for Programmers New to PureB

Posted: Thu Jul 02, 2020 9:03 am
by infratec
loulou2522 wrote:I think it will be necessary to show how to install a postgresql server.
That's not PB related :wink:

Re: Sample Database Application for Programmers New to PureB

Posted: Thu Jul 02, 2020 10:19 am
by IdeasVacuum