Example #1
0
	def __init__(self, connectInfo=None, parent=None, forceCreate=False, **kwargs):
		self._baseClass = dConnection
		self._forceCreate = forceCreate
		super(dConnection, self).__init__()
		# Store a reference to the parent object (bizobj maybe; app
		# object connection collection most likely)
		self.Parent = parent

		if connectInfo is None:
			# Fill it in from any kwargs (will get converted to a dConnectInfo
			# object in the block below).
			connectInfo = kwargs

		if isinstance(connectInfo, dConnectInfo):
			self._connectInfo = connectInfo
		elif connectInfo:
			# If they passed a cnxml file, or a dict containing valid connection info,
			# this will work fine. Otherwise, an error will be raised in the
			# dConnectInfo class.
			self._connectInfo = dConnectInfo(connInfo=connectInfo)
		else:
			raise TypeError("dConnectInfo instance or kwargs not sent.")
		self._connection = self._openConnection(**kwargs)
Example #2
0
	def _getName(self):
		try:
			return self.ConnectInfo.Name
		except AttributeError:
			return "?"


	ConnectInfo = property(_getConnInfo, None, None,
			_("The connectInfo for the connection.  (dConnectInfo)"))

	Name = property(_getName, None, None,
			_("The name of the connection.  (str)"))



if __name__ == "__main__":
	from dConnectInfo import dConnectInfo
	ci = dConnectInfo(DbType="MySQL")
	ci.Host = "paulmcnett.com"
	ci.Database = "dabotest"
	ci.User = "******"
	ci.PlainTextPassword = "******"

	conn = dConnection(ci).getConnection()
	cursor = conn.cursor()
	print cursor.execute("select * from recipes order by iid limit 10")
	for row in cursor.fetchall():
		print row[0], row[1]