Hi all,

Is there a buffer size or similar optimization parameter that can be set for QSqlDatabase PSQL connections? The docs refer to PostgreSQL "options" without specifying what they may be.

I have a PG database cluster of about 7MB, spread over a couple dozen tables. Locally, it takes about 6 seconds to launch my app, loading the model data into my forms.

When I pull an identical data-set from a remote location, my application launch time increases to over 60 seconds. Yet resource utilization on the remote server is miniscule.

For comparison, I'm able to download the results of a 21MB SELECT statement in less than 8 seconds via cmd-line psql. That's orders of magnitude more data in an order of magnitude less time!

I'm creating my db connection as follows.  (Sample code attached also.)

        db = QtSql.QSqlDatabase.addDatabase("QPSQL")
        db.setDatabaseName("fubar")
        db.setHostName("localhost")
        db.setUserName("admin")
        db.setPassword("abc123")


Thanks in advance!
Scott


#!/usr/bin/env python


#-------------------------------------------------------------------------------
# imports
#-------------------------------------------------------------------------------
import sys, os
from PyQt4 import QtCore, QtGui, QtSql



#-------------------------------------------------------------------------------
# enum
#-------------------------------------------------------------------------------
COLOR_ID, NAME, DESCRIPTION = range(3)



#-------------------------------------------------------------------------------
# schema
#-------------------------------------------------------------------------------
def createFakeData():

	query       = QtSql.QSqlQuery()

	print "Dropping table..."
	query.exec_("DROP TABLE color")

	print "Creating table..."

	err1 = query.exec_("""CREATE TABLE color (
				color_id INTEGER PRIMARY KEY,
				name VARCHAR(20) NOT NULL,
				description VARCHAR(40) NOT NULL)""")

	print "Populating table..."

	err2 = query.exec_("INSERT INTO color (color_id, name, description) "
				"VALUES (1, 'red', 'this is red')")

	query.exec_("INSERT INTO color (color_id, name, description) "
				"VALUES (2, 'green', 'this is green')")

	query.exec_("INSERT INTO color (color_id, name, description) "
				"VALUES (3, 'blue', 'this is blue')")



#-------------------------------------------------------------------------------
# class
#-------------------------------------------------------------------------------
class QueryTestForm(QtGui.QWidget):
	def __init__(self, parent=None):
		QtGui.QWidget.__init__(self)



		# table model
		# ------------------------------------------------
		self.theModel = QtSql.QSqlTableModel(self)
		self.theModel.setTable("color")
		self.theModel.setSort(NAME, QtCore.Qt.AscendingOrder)
		self.theModel.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)

		# column headers
		self.theModel.setHeaderData(COLOR_ID, QtCore.Qt.Horizontal, QtCore.QVariant("COLOR_ID"))
		self.theModel.setHeaderData(NAME, QtCore.Qt.Horizontal, QtCore.QVariant("NAME"))
		self.theModel.setHeaderData(DESCRIPTION, QtCore.Qt.Horizontal, QtCore.QVariant("DESCRIPTION"))

		select = self.theModel.select()



		# table view
		# ------------------------------------------------
		self.theView = QtGui.QTableView()
		self.theView.setSortingEnabled(True)
		self.theView.setModel(self.theModel)
		self.theView.setSelectionMode(QtGui.QTableView.SingleSelection)
		self.theView.setSelectionBehavior(QtGui.QTableView.SelectRows)
		self.theView.setColumnHidden(COLOR_ID, True)
		self.theView.resizeColumnsToContents()
		self.theView.horizontalHeader().setStretchLastSection(True)



		# table layout
		# ------------------------------------------------		
		self.tableLayout		= QtGui.QVBoxLayout()
		self.tableLayout.addWidget(self.theView)
		self.setLayout(self.tableLayout)



		# table view selection model
		# ------------------------------------------------
		self.theSelectionModel = self.theView.selectionModel()






#-------------------------------------------------------------------------------
# main
#-------------------------------------------------------------------------------
if __name__ == "__main__":
	app = QtGui.QApplication(sys.argv)

	db = QtSql.QSqlDatabase.addDatabase("QPSQL")
	db.setDatabaseName("fubar")
	db.setHostName("localhost")
	db.setUserName("admin")
	db.setPassword("abc123")

	if not db.open():
		QtGui.QMessageBox.warning(None, "Test",
			QtCore.QString("Database Error: %1").arg(db.lastError().text()))
		sys.exit(1)
	
	ok = db.open()
	print "db connection:	", ok

	createFakeData()
	form = QueryTestForm()
	form.setWindowTitle("Database Test")
	form.show()
	sys.exit(app.exec_())
		



_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to