<div dir="ltr">Have you tried just setting it to None?<div><br></div><div>- Nathan</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 30, 2013 at 7:38 PM, Alexandre Neto <span dir="ltr"><<a href="mailto:senhor.neto@gmail.com" target="_blank">senhor.neto@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In the multipartsplit plugin [1] I'm trying to solve the primary key (pk) fields problem in postgis and spatialite like in it was done in the splitFeatures() [2]<div>

<br></div><div>I have no problems with Postgis provider, but in spatialite setting pk fields to NULL does not work as I expected, and spatialite does not choose a new non used id by it self. (Making it impossible to commit the changes without manually introduce some id)</div>



<div><br></div><div>In splitFeatures() [2] when a field is in <a href="http://www.qgis.org/api/classQgsVectorDataProvider.html#a6e19d018aa0b88da21fdb9d02c5e8a60" title="Return list of indexes of fields that make up the primary key." style="font-family:monospace,fixed;font-size:9pt;line-height:15px;color:rgb(70,101,162);text-decoration:none" target="_blank">provider.pkAttributeIndexes</a><span style="line-height:15px;font-size:9pt;background-color:rgb(251,252,253);font-family:monospace,fixed">(), </span>but has no default value, the filed is set to empty with this</div>


<div><br></div><div><pre style="line-height:15px;overflow:auto;font-size:9pt;background-color:rgb(251,252,253);margin:4px 8px 4px 2px;font-family:monospace,fixed;word-wrap:break-word;padding:4px 6px;border:1px solid rgb(196,207,229)">

newAttributes[ pkIdx ] = QVariant();</pre></div>
<div><br></div><div>But i'm not being able to use it in my code, since it's says QVariant() can not be instantiated. Actually this is said in here [3]. And it says that Null QVariant() are now converted in <span style="color:rgb(48,48,48);font-family:Verdana,Tahoma,Arial,sans-serif;font-size:12px">QPyNullVariant</span></div>


<div><br></div><div>Can I use <font color="#303030" face="Verdana, Tahoma, Arial, sans-serif"><span style="font-size:12px">QPyNullVariant to keep the pk field empty, so that spatialite automatically choose a adequate int value? How?</span></font></div>


<div><font color="#303030" face="Verdana, Tahoma, Arial, sans-serif"><span style="font-size:12px"><br></span></font></div><div><font color="#303030" face="Verdana, Tahoma, Arial, sans-serif"><span style="font-size:12px">I tried the code bellow but it did not work.</span></font></div>


<div><font face="courier new, monospace"><br></font></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<font face="courier new, monospace"># Get attributes from original feature<br>new_attributes = feature.attributes()<br></font></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<font face="courier new, monospace"># When attribute is a Primary Key, replace by provider default value</font></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<font face="courier new, monospace">for j in provider.pkAttributeIndexes():<br>    if provider.defaultValue(j):<br>        new_attributes[j] = provider.defaultValue(j)<br>    else:<br>        new_attributes[j] = QPyNullVariant('int')</font></blockquote>


</div><div><br></div><div><br></div><div>Thanks.</div><div><br></div><div>Alexandre Neto</div><div><br></div><div>[1] <a href="http://plugins.qgis.org/plugins/splitmultipart/" target="_blank">http://plugins.qgis.org/plugins/splitmultipart/</a></div>



<div>[2] <a href="http://www.qgis.org/api/qgsvectorlayereditutils_8cpp_source.html#l00247" target="_blank">http://www.qgis.org/api/qgsvectorlayereditutils_8cpp_source.html#l00247</a></div><div>[3] <a href="http://hub.qgis.org/wiki/quantum-gis/Python_plugin_API_changes_from_18_to_20" target="_blank">http://hub.qgis.org/wiki/quantum-gis/Python_plugin_API_changes_from_18_to_20</a></div>


<div><br></div><div><br></div>
</div>
<br>_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br></blockquote></div><br></div>