[Modeling-cvs] SF.net SVN: modeling: [994] trunk/ProjectModeling
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2006-04-19 19:39:32
|
Revision: 994 Author: sbigaret Date: 2006-04-19 12:39:18 -0700 (Wed, 19 Apr 2006) ViewCVS: http://svn.sourceforge.net/modeling/?rev=994&view=rev Log Message: ----------- Fix for bug #1471992: objects w/ values containing a single backslash are not properly handled by the MySQL and Postgresql adaptor layers Modified Paths: -------------- trunk/ProjectModeling/CHANGES trunk/ProjectModeling/Modeling/DatabaseAdaptors/MySQLAdaptorLayer/MySQLSQLExpression.py trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/PostgresqlSQLExpression.py trunk/ProjectModeling/Modeling/tests/test_EditingContext_Global.py Modified: trunk/ProjectModeling/CHANGES =================================================================== --- trunk/ProjectModeling/CHANGES 2006-04-15 09:48:43 UTC (rev 993) +++ trunk/ProjectModeling/CHANGES 2006-04-19 19:39:18 UTC (rev 994) @@ -7,6 +7,11 @@ ** Distributed under a 3-clause BSD-style license, see LICENSE for details ** ----------------------------------------------------------------------------- + * Fixed bug #1471992: objects w/ values containing a single backslash are + not properly handled by the MySQL and Postgresql adaptor layer (the + generated SQLExpression are incorrect; for example, insertions of such + objects failed) + * Fixed bug #621210: when __cmp__ (and/or, possibly, other special methods such as __eq__ or __ne__) was defined in a CustomObject, it was possible to enter a infinite loop. The fix consisted in making sure that the Modified: trunk/ProjectModeling/Modeling/DatabaseAdaptors/MySQLAdaptorLayer/MySQLSQLExpression.py =================================================================== --- trunk/ProjectModeling/Modeling/DatabaseAdaptors/MySQLAdaptorLayer/MySQLSQLExpression.py 2006-04-15 09:48:43 UTC (rev 993) +++ trunk/ProjectModeling/Modeling/DatabaseAdaptors/MySQLAdaptorLayer/MySQLSQLExpression.py 2006-04-19 19:39:18 UTC (rev 994) @@ -235,7 +235,24 @@ else: return SQLExpression.sqlStringForSelector(self, selector, value) + def sqlStringForString(self, aString): + """ + Formats 'aString' and returns the string suitable for inclusion in a SQL + statement. SQLExpression's implementation surrounds the string with + simple quotes, and back-quotes any simple quotes 'aString' may have. + It returns 'NULL' if 'aString' is None. + See also: formatValueForAttribute() + """ + if aString is not None: + # quote the string: interprets the strings + aString = repr(aString)[1:-1] + from Modeling.SQLExpression import escapeQuote + str=escapeQuote.sub("\\'", aString) + return "'"+str+"'" + else: + return 'NULL' + if mysql_server_version()[:2]>=(4,0): MySQLSQLExpression.SQL92_join=1 else: Modified: trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/PostgresqlSQLExpression.py =================================================================== --- trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/PostgresqlSQLExpression.py 2006-04-15 09:48:43 UTC (rev 993) +++ trunk/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/PostgresqlSQLExpression.py 2006-04-19 19:39:18 UTC (rev 994) @@ -25,20 +25,7 @@ from Modeling.SQLExpression import SQLExpression, DateType, CharacterType import string -import re -esc_question_tmp_replct='MDL_ESCAPED_QUESTION_MARK_MDL' -esc_star_tmp_replct='MDL_ESCAPED_STAR_MDL' - -star=re.compile('\*') -escaped_star=re.compile(r'\\\*') -question_mark=re.compile('\?') -escaped_question_mark=re.compile(r'\\\?') -percent=re.compile('%') -underscore=re.compile('_') -anti_escaped_star=re.compile(esc_star_tmp_replct) -anti_esc_question_mark=re.compile(esc_question_tmp_replct) - class PostgresqlSQLExpression(SQLExpression): """ @@ -46,6 +33,25 @@ valueTypeForExternalTypeMapping() to add some new """ + def ____addInsertListAttribute(self, attribute, value): + """ + + Parameters: + + attribute -- an Attribute object + + value -- the value to store + + """ + sqlAttr=self.sqlStringForAttributeNamed(attribute.name()) + sqlValue=self.sqlStringForValue(value, attribute.name()) + #print '### sqlAttr: %s / sqlValue: %s'%(sqlAttr, sqlValue) + self.appendItemToListString(sqlAttr, self._listString) + import pdb ; pdb.set_trace() + if type(sqlValue) is type(''): + sqlValue = repr(sqlValue) + self.appendItemToListString(sqlValue, self._valueList) + def columnTypeStringForAttribute(self, attribute): """ Overrides default implementation to handle TEXT field properly. @@ -107,21 +113,24 @@ """ return '\\\\' - def sqlPatternFromShellPatternWithEscapeCharacter(self, pattern, escapeChar): + def sqlStringForString(self, aString): """ - Overrides default behaviour so that '%' is changed to '\\%' instead of - '\%': postgresql interprets backslashes in strings + Formats 'aString' and returns the string suitable for inclusion in a SQL + statement. SQLExpression's implementation surrounds the string with + simple quotes, and back-quotes any simple quotes 'aString' may have. + It returns 'NULL' if 'aString' is None. + + See also: formatValueForAttribute() """ - pattern=percent.sub(r'\\\\%', pattern) - pattern=underscore.sub(r'\\\\_', pattern) - pattern=escaped_question_mark.sub(esc_question_tmp_replct, pattern) - pattern=question_mark.sub('_', pattern) - pattern=escaped_star.sub(esc_star_tmp_replct, pattern) - pattern=star.sub('%', pattern) - pattern=anti_escaped_star.sub('*', pattern) - pattern=anti_esc_question_mark.sub('?', pattern) - return pattern - + if aString is not None: + # quote the string: postgresql interprets the strings + aString = repr(aString)[1:-1] + from Modeling.SQLExpression import escapeQuote + str=escapeQuote.sub("\\'", aString) + return "'"+str+"'" + else: + return 'NULL' + def valueTypeForExternalTypeMapping(self): """ Modified: trunk/ProjectModeling/Modeling/tests/test_EditingContext_Global.py =================================================================== --- trunk/ProjectModeling/Modeling/tests/test_EditingContext_Global.py 2006-04-15 09:48:43 UTC (rev 993) +++ trunk/ProjectModeling/Modeling/tests/test_EditingContext_Global.py 2006-04-19 19:39:18 UTC (rev 994) @@ -1414,22 +1414,31 @@ self.failUnless(rabelais.isFault()) rabelais.getLastName() - def _test_29_fetch_backslash(self): + def test_30_fetch_backslash(self): "[EditingContext] fetch real backslash" # bug # ec=EditingContext() - b1=Book(); b1.setTitle(r'abc\n') - b2=Book(); b2.setTitle('abc\\\\') - b3=Book(); b3.setTitle('\\') - ec.insert(b1); ec.insert(b2); ec.insert(b3) + b1=Book(); b1.setPrice(1.0); b1.setTitle(r'abc\n') + b2=Book(); b2.setPrice(2.0); b2.setTitle('abc\n') + b3=Book(); b3.setPrice(3.0); b3.setTitle('\\') + b4=Book(); b4.setPrice(4.0); b4.setTitle(r'\\') + ec.insert(b1); ec.insert(b2); ec.insert(b3); ec.insert(b4) ec.saveChanges() res=ec.fetch('Book', 'title == "abc\\n"') self.assertEqual(len(res), 1) self.assertEqual(res[0].getTitle(), r"abc\n") + self.assertEqual(res[0].getPrice(), 1) + + res=ec.fetch('Book', 'title == "abc\n"') + self.assertEqual(len(res), 1) + self.assertEqual(res[0].getTitle(), "abc\n") + self.assertEqual(res[0].getPrice(), 2) + res=ec.fetch('Book', 'title == "\\"') self.assertEqual(len(res), 1) self.assertEqual(res[0].getTitle(), "\\") + self.assertEqual(res[0].getPrice(), 3) #res=ec.fetch('Book', 'title like "*abc%d*"') #self.assertEqual(len(res), 1) #self.assertEqual(res[0].getTitle(), "abc%d") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |