<typesystem package="com.trolltech.qt.sql" default-superclass="com.trolltech.qt.QtJambiObject">
  <inject-code>
    com.trolltech.qt.Utilities.loadQtLibrary("QtSql");
  </inject-code>

  <rejection class="QSqlDriverCreator" />
  <rejection class="QSqlDriverPlugin" />
  <rejection class="QSqlDriverFactoryInterface" />

  <namespace-type name="QSql">
     <include file-name="qsql.h" location="global" />
  </namespace-type>
  
  <value-type name="QSqlDatabase">
    <extra-includes>
        <include file-name="QSqlQuery" location="global" />
        <include file-name="QSqlError" location="global" />
        <include file-name="QSqlIndex" location="global" />
        <include file-name="QSqlRecord" location="global" />
        <include file-name="QStringList" location="global" />
        <include file-name="QSize" location="global" />
    </extra-includes>  
    <modify-function signature="addDatabase(QSqlDriver*,QString)">
        <modify-argument index="1">
            <define-ownership class="java" owner="c++" />
        </modify-argument>
    </modify-function>
    <modify-function signature="contains(QString)">
        <modify-argument index="1">
            <replace-default-expression with="defaultConnection()" />
        </modify-argument>
    </modify-function>
    <modify-function signature="addDatabase(QString,QString)">
        <modify-argument index="2">
            <replace-default-expression with="defaultConnection()" />
        </modify-argument>
    </modify-function>
    <modify-function signature="addDatabase(QSqlDriver *,QString)">
        <modify-argument index="2">
            <replace-default-expression with="defaultConnection()" />
        </modify-argument>
    </modify-function>
    <modify-function signature="database(QString,bool)">
        <modify-argument index="1">
            <replace-default-expression with="defaultConnection()" />
        </modify-argument>
    </modify-function>
    
    <modify-function signature="operator=(QSqlDatabase)" remove="all"/>
    <modify-field name="defaultConnection">
        <access modifier="private"/>
        <rename to="defaultConnection_private" />
    </modify-field>
    <inject-code>
        public static String defaultConnection() {
            com.trolltech.qt.QNativePointer np = defaultConnection_private();
            
            String returned = "";
            int i=0;
            while (np.byteAt(i) != 0) returned += (char) np.byteAt(i++);
            return returned;            
        }
    </inject-code>
  </value-type>  

  <value-type name="QSqlQuery">
    <extra-includes>
        <include file-name="QSqlError" location="global" />
        <include file-name="QSqlRecord" location="global" />
        <include file-name="QStringList" location="global" />
        <include file-name="QSize" location="global" />
    </extra-includes>  
    <modify-function signature="operator=(QSqlQuery)" remove="all"/>
  </value-type>  

  <value-type name="QSqlRecord">
    <extra-includes>
        <include file-name="QSqlField" location="global" />
    </extra-includes>
    <modify-function signature="append(QSqlField)" access="non-final"/>
    <modify-function signature="operator=(QSqlRecord)" remove="all"/>
  </value-type>

  <value-type name="QSqlError">
    <modify-function signature="operator=(QSqlError)" remove="all"/>
  </value-type>

  <value-type name="QSqlIndex">  
    <modify-function signature="operator=(QSqlIndex)" remove="all"/>
  </value-type>

  <value-type name="QSqlRelation" />

  <value-type name="QSqlField">
    <modify-function signature="operator=(QSqlField)" remove="all"/>
  </value-type>  
  
  <object-type name="QSqlDriver">  
    <extra-includes>
        <include file-name="QSqlQuery" location="global" />
        <include file-name="QSqlError" location="global" />
        <include file-name="QSqlIndex" location="global" />
        <include file-name="QSqlRecord" location="global" />
        <include file-name="QStringList" location="global" />
        <include file-name="QSize" location="global" />
    </extra-includes>  
  </object-type>  
  
  <object-type name="QSqlQueryModel">    
    <modify-function signature="indexInQuery(QModelIndex)const" access="non-final"/>
    <modify-function signature="setQuery(QSqlQuery)" access="non-final"/>
    <extra-includes>
        <include file-name="QSqlError" location="global" />
        <include file-name="QSqlQuery" location="global" />
        <include file-name="QSqlRecord" location="global" />
        <include file-name="QStringList" location="global" />
        <include file-name="QSize" location="global" />
    </extra-includes>  
  </object-type>      
  <object-type name="QSqlRelationalTableModel">
    <extra-includes>
        <include file-name="QStringList" location="global" />
        <include file-name="QSize" location="global" />
    </extra-includes>  
  </object-type>
  <object-type name="QSqlResult">
      <extra-includes>
        <include file-name="QSqlError" location="global" />
        <include file-name="QSqlQuery" location="global" />
        <include file-name="QSqlRecord" location="global" />
        <include file-name="QStringList" location="global" />
        <include file-name="QSize" location="global" />
      </extra-includes>
      <modify-function signature="virtual_hook(int,void*)">
        <remove />
      </modify-function>
      
  </object-type>
  <object-type name="QSqlTableModel">  
    <extra-includes>
        <include file-name="QSqlIndex" location="global" />
        <include file-name="QStringList" location="global" />
        <include file-name="QSize" location="global" />
    </extra-includes>  

    <template name="sql.convert_sqlrecord_reference_to_java">
        jobject %out = qtjambi_from_object(__jni_env, &amp;%in, "QSqlRecord", "com/trolltech/qt/sql/", false);
        Q_ASSERT(%out);
    </template>
    
    <template name="sql.convert_sqlrecord_reference_from_java">
        QSqlRecord *__ptr_record = (QSqlRecord *) qtjambi_to_object(__jni_env, %in);
        
        QSqlRecord dummy;
        QSqlRecord &amp;%out = __ptr_record == 0 ? dummy : *__ptr_record;
    </template>
    
    <modify-function signature="beforeInsert(QSqlRecord&amp;)">
        <modify-argument index="1">
            <replace-type modified-type="com.trolltech.qt.sql.QSqlRecord" />
            <conversion-rule class="shell">
                <insert-template name="sql.convert_sqlrecord_reference_to_java" />
            </conversion-rule>
            <conversion-rule class="native">
                <insert-template name="sql.convert_sqlrecord_reference_from_java" />
            </conversion-rule>            
        </modify-argument>
    </modify-function>
    
    <modify-function signature="beforeUpdate(int,QSqlRecord&amp;)">
        <modify-argument index="2">
            <replace-type modified-type="com.trolltech.qt.sql.QSqlRecord" />
            <conversion-rule class="shell">
                <insert-template name="sql.convert_sqlrecord_reference_to_java" />
            </conversion-rule>
            <conversion-rule class="native">
                <insert-template name="sql.convert_sqlrecord_reference_from_java" />
            </conversion-rule>            
        </modify-argument>
    </modify-function>
    
    <modify-function signature="primeInsert(int,QSqlRecord&amp;)">
        <modify-argument index="2">
            <replace-type modified-type="com.trolltech.qt.sql.QSqlRecord" />
            <conversion-rule class="shell">
                <insert-template name="sql.convert_sqlrecord_reference_to_java" />
            </conversion-rule>
            <conversion-rule class="native">
                <insert-template name="sql.convert_sqlrecord_reference_from_java" />
            </conversion-rule>            
        </modify-argument>
    </modify-function>
  </object-type>  
  <object-type name="QSqlDriverCreatorBase">
    <extra-includes>
        <include file-name="QSqlDriver" location="global" />
    </extra-includes>    
  </object-type>
  
  <enum-type name="QSql::Location" />
  <enum-type name="QSql::ParamTypeFlag" flags="QSql::ParamType" />
  <enum-type name="QSql::TableType" />
  <enum-type name="QSql::NumericalPrecisionPolicy" />
  <enum-type name="QSqlDriver::DriverFeature" />
  <enum-type name="QSqlDriver::IdentifierType" />
  <enum-type name="QSqlDriver::StatementType" />
  <enum-type name="QSqlError::ErrorType" />
  <enum-type name="QSqlField::RequiredStatus" />
  <enum-type name="QSqlQuery::BatchExecutionMode"/>
  <enum-type name="QSqlResult::BindingSyntax" />
  <enum-type name="QSqlResult::VirtualHookOperation" />
  <enum-type name="QSqlTableModel::EditStrategy" />

  <suppress-warning text="WARNING(CppImplGenerator) :: protected function '*' in final class '*'" />
  <suppress-warning text="WARNING(MetaJavaBuilder) :: visibility of function '*' modified in class '*'" />  
  <suppress-warning text="WARNING(MetaJavaBuilder) :: hiding of function '*' in class '*'" />    
  <suppress-warning text="WARNING(MetaJavaBuilder) :: Class 'QSqlField' has equals operators but no qHash() function" />
  <suppress-warning text="WARNING(MetaJavaBuilder) :: Class 'QSqlRecord' has equals operators but no qHash() function" />

</typesystem>
