Good day! I am writing a stored function for Postgre as a C ++ Qt library. Among other things, this library will have to be able to make queries to the database from which it was called. If you enter the login, password and database in the code, such as this:

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); db.setDatabaseName("test"); db.setUserName("postgres"); db.setPassword("123456"); 

Then everything is perfectly connected and working. But the problem is that I cannot know in advance from which database and from which user this library was called. Is there any way around this? Thank!

  • does not reach, if it is function then why not to transfer to it parameters? - maint
  • @maint That's the trick, from the database itself is also not possible to get the user password from which the connection is being made. Well, at least I have not found this. - Pavel Vershinin

1 answer 1

Everything turned out to be much easier! As it turned out, to access the database from the library, it is generally not required to know anything about the database, or the user. It is enough to connect to the project executor/spi.h and voila, we can safely work with the database from the context of which the library was called.

http://postgresql.ru.net/manual/spi-examples.html