I am building a plugin for QGIS which will have a combo box listing data from PostGreSQL. I have already connected PostGreSQL. Now I would want to make this a plugin and add the list of jobs to the combo box .
import psycopg2
from PyQt4.QtGui import*
from qgis.core import QgsMessageLog
msg = QMessageBox()
msg.setText("Message Box Created")
msg.show()
try:
connection = psycopg2.connect(user = "****",
password = "********",
host = "******",
port = "******",
database = "******")
cursor = connection.cursor()
# Print PostgreSQL Connection properties
print("connected")
#print ( connection.get_dsn_parameters(),"\n")
# Print PostgreSQL version
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record,"\n")
#creating table in database
'''create_table_query = CREATE TABLE TEST
(ID INT PRIMARY KEY NOT NULL,
job_desc TEXT NOT NULL,
username REAL);
cursor.execute(create_table_query)'''
connection.commit()
print("Table created successfully in PostgreSQL ")
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")