[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/koffice/1.6/koffice/kexi/kexidb
From:       Jaroslaw Staniek <js () iidea ! pl>
Date:       2006-09-14 20:52:53
Message-ID: 1158267173.534612.15627.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 584434 by staniek:

KexiDB
- do not try to insert default values into a column with unique 
  flag declared (or even PK) 

2.0: merged



 M  +4 -1      connection.cpp  
 M  +3 -2      roweditbuffer.cpp  
 M  +4 -2      roweditbuffer.h  
 M  +5 -0      utils.cpp  
 M  +5 -0      utils.h  


--- branches/koffice/1.6/koffice/kexi/kexidb/connection.cpp #584433:584434
@@ -3067,7 +3067,10 @@
 	const QueryColumnInfo::Vector fieldsExpanded( query.fieldsExpanded( \
QuerySchema::Unique ) );  for (uint i=0; i<fieldsExpanded.count(); i++) {
 		QueryColumnInfo *ci = fieldsExpanded.at(i);
-		if (ci->field && !ci->field->defaultValue().isNull() && !b.contains( ci )) {
+		if (ci->field && KexiDB::isDefaultValueAllowed(ci->field) 
+			&& !ci->field->defaultValue().isNull() 
+			&& !b.contains( ci ))
+		{
 			KexiDBDbg << "Connection::insertRow(): adding default value '" << \
ci->field->defaultValue().toString()  << "' for column '" << ci->field->name() << "'" \
<< endl;  b.insert( ci, ci->field->defaultValue() );
--- branches/koffice/1.6/koffice/kexi/kexidb/roweditbuffer.cpp #584433:584434
@@ -17,7 +17,8 @@
  * Boston, MA 02110-1301, USA.
 */
 
-#include <kexidb/roweditbuffer.h>
+#include "roweditbuffer.h"
+#include "utils.h"
 
 #include <kdebug.h>
 
@@ -55,7 +56,7 @@
 		result = &(*m_dbBufferIt).data();
 	if ( useDefaultValueIfPossible 
 		&& (!result || result->isNull()) 
-		&& ci.field && !ci.field->defaultValue().isNull()
+		&& ci.field && !ci.field->defaultValue().isNull() && \
KexiDB::isDefaultValueAllowed(ci.field)  && !hasDefaultValueAt(ci) )
 	{
 		//no buffered or stored value: try to get a default value declared in a field, so \
                user can modify it
--- branches/koffice/1.6/koffice/kexi/kexidb/roweditbuffer.h #584433:584434
@@ -98,8 +98,10 @@
 		{ if (m_simpleBuffer) m_simpleBuffer->insert(fname,val); }
 
 	/*! Useful only for db-aware buffer. \return value for column \a ci
-	 If there is no value assigned for the buffer, this method tries to return
-	 default value obtained from \a ci if \a useDefaultValueIfPossible is true. */
+	 If there is no value assigned for the buffer, this method tries to remember and \
return +	 default value obtained from \a ci if \a useDefaultValueIfPossible is true. 
+	 Note that if the column is declared as unique (especially: primary key), 
+	 default value will not be used. */
 	const QVariant* at( QueryColumnInfo& ci, bool useDefaultValueIfPossible = true ) \
const;  
 	//! Useful only for not-db-aware buffer. \return value for field \a f
--- branches/koffice/1.6/koffice/kexi/kexidb/utils.cpp #584433:584434
@@ -1081,4 +1081,9 @@
 	return result;
 }
 
+bool KexiDB::isDefaultValueAllowed( KexiDB::Field* field )
+{
+	return field && !field->isUniqueKey();
+}
+
 #include "utils_p.moc"
--- branches/koffice/1.6/koffice/kexi/kexidb/utils.h #584433:584434
@@ -376,6 +376,11 @@
 	 \ref variantToString( const QVariant& v ) function.
 	 \a ok is set to the result of the operation. */
 	KEXI_DB_EXPORT QVariant stringToVariant( const QString& s, QVariant::Type type, \
bool &ok ); +
+	/*! \return true if setting default value for \a field field is allowed. Fields \
with unique  +	 (and thus primary key) flags set do not accept  default values. 
+	 False is returned aslo if \a field is 0. */
+	KEXI_DB_EXPORT bool isDefaultValueAllowed( KexiDB::Field* field );
 }
 
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic