PureBasic Forum
https://www.purebasic.fr/english/

Sample Database Application for Programmers New to PureBasic
https://www.purebasic.fr/english/viewtopic.php?f=27&t=70998
Page 2 of 2

Author:  jcaceres [ Wed Jul 01, 2020 6:40 am ]
Post subject:  Re: Sample Database Application for Programmers New to PureB

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.

Author:  infratec [ Wed Jul 01, 2020 7:50 am ]
Post subject:  Re: Sample Database Application for Programmers New to PureB

I think this is a good starting point:
Code:
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:
DB = OpenDatabase(#PB_Any, "host=127.0.0.1 dbname=Test port=5432", "User", "Password")

Author:  loulou2522 [ Thu Jul 02, 2020 9:01 am ]
Post subject:  Re: Sample Database Application for Programmers New to PureB

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

Author:  infratec [ Thu Jul 02, 2020 9:03 am ]
Post subject:  Re: Sample Database Application for Programmers New to PureB

loulou2522 wrote:
I think it will be necessary to show how to install a postgresql server.


That's not PB related :wink:

Author:  IdeasVacuum [ Thu Jul 02, 2020 10:19 am ]
Post subject:  Re: Sample Database Application for Programmers New to PureB

https://www.postgresqltutorial.com/install-postgresql

Page 2 of 2 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/