def getDBTablesFieldsList(self,tableName):
		""" returns list of tableName table fields """
		request = FSZSQLMethod(self,self._DBTableEntriesZSQLFile)
		request.connection = self.connection
		request.connection.manage_open_connection()
		result = request(tableName=tableName)
		request.connection.manage_close_connection()
		return result.names()
	def _getTablePkeys(self,tableName):
		""" returns the name of table primary keys """
		pkeylistRequest = FSZSQLMethod(self,self._DBTablePkeyZSQLFile)
		pkeylistRequest.connection = self.connection
		pkeylistRequest.connection.manage_open_connection()
		pkeylistResults = pkeylistRequest(tableName=tableName)
		tableKeys = tuple()
		for pkeylistResult in pkeylistResults:
			tableKeys += (pkeylistResult['field'],)
		pkeylistRequest.connection.manage_close_connection()
		return tableKeys
	def getDBTablesList(self):
		""" returns the tables of the database (psycopg) - only ones that may be interesting for making forms string list """
		if not hasattr(self,"connection"):
			return []
		
		else:
			request = FSZSQLMethod(self,self._DBTablesListZSQLFile)
			request.connection = self.connection
			request.connection.manage_open_connection()
			tablesList = [result['tablename'] for result in request() \
				if not(result['tablename'].startswith("pg_") or result['tablename'].startswith("sql_"))]
			request.connection.manage_close_connection()
			return tablesList
	def getDBStructure(self,):
		""" psycopg version
		
		structure :

    {<tableName_str>:
        {<fieldName_str>:
             {'primary_key':<boolean>,'width':<integer>,'null':<boolean>,'foreign_key':(<table_str>,<field_str>),'type':<str>,'auto_num':<bool>}
         },
 ...}
"""
		structure = {}

		fieldslistRequest = FSZSQLMethod(self,self._DBTableFieldsZSQLFile)
		fieldslistRequest.connection = self.connection
		fieldslistRequest.connection.manage_open_connection()
		
		for table in self.getDBTablesList():
			
			if self._DBStructure:
				if self._DBStructure.has_key(table):
					if self._DBStructure[table]: # use saved config if exists
						structure[table] = self._DBStructure[table]
						break
			
			structure[table] = {}
			fieldslistResult = fieldslistRequest(tableName=table)
			
			tablePkey = self._getTablePkeys(table)
			
			for field in fieldslistResult:
				
				fieldDefs = {}
				fieldDefs['primary_key'] = (field['field'] in tablePkey)
				fieldDefs['foreign_key'] = False # TODO
				fieldDefs['auto_num'] = False # TODO
				fieldDefs['width'] = self._DBType2len[field['type']]
				fieldDefs['null'] = field['not_null'] or fieldDefs['primary_key']
				fieldDefs['type'] = field['type']
				fieldDefs['unique'] = False # TODO
				fieldDefs['label'] = self.labelFromId(field['field'])
	
				structure[table][field['field']]=fieldDefs
		
		fieldslistRequest.connection.manage_close_connection()
		
		self._DBStructure = structure
		return structure
Example #5
0
 def _makeOne(self, id, filename):
     path = join(self.skin_path_name, filename)
     metadata = FSMetadata(filepath=path)
     metadata.read()
     return FSZSQLMethod(id,
                         filepath=path,
                         properties=metadata.getProperties())
	def idSearch(self,fieldId="",userValue="",tableName=""):
		if not(tableName) and hasattr(self,'tableName'):
			tableName = self.tableName
		
		idSearchRequest = FSZSQLMethod(self,self._IDSearchZSQLFile)
		idSearchRequest.connection = self.connection
		idSearchRequest.connection.manage_open_connection()
		idSearchResults = idSearchRequest(fieldId=fieldId,userValue=str(userValue),tableName=tableName)
		idSearchRequest.connection.manage_close_connection()
		
		if len(idSearchResults) > 1:
			raise "the couple "+fieldId+"/"+userValue+" doesn't make a primary key"
			
		elif len(idSearchResults) < 1:
			return None
		else:
			return idSearchResults[0]
	def createDbEntry(self,parent,fieldsValuesDictionary=None):
		""" feeds the table with datas from the public form """
		
		# SOMETHING I'M TOO YOUNG TO UNDERSTAND : 
		# ACQUISITION DOESNT WORKS UNTIL THE END OF THE CREATION TRANSACTION
		
		tableName = self.getTableName()
		projectId = parent.getProject_db_id() 
		tablePkey = self.getTablePkey()
		userName = parent.portal_membership.getAuthenticatedMember().getId()
		
		creationRequest = FSZSQLMethod(self,self._FirstAddRequestFile)
		creationRequest.connection = parent.connection
		
		logSQL = creationRequest(projectId=projectId,tablePkey=tablePkey,tableName=tableName,userName=userName,fieldsValuesDictionary=fieldsValuesDictionary,src__=1)
		
		self.log = str(fieldsValuesDictionary) + logSQL
		
		creationRequest(projectId=projectId,tablePkey=tablePkey,tableName=tableName,userName=userName,fieldsValuesDictionary=fieldsValuesDictionary)
Example #8
0
 def _makeOne(self, id, filename):
     from Products.CMFCore.FSZSQLMethod import FSZSQLMethod
     path = join(self.skin_path_name, filename)
     metadata = FSMetadata(path)
     metadata.read()
     return FSZSQLMethod(id, path, properties=metadata.getProperties())