LCOV - code coverage report
Current view: top level - data/source/storage - data_visible_classifier_iterator.c (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.63.2_covts Lines: 94.7 % 76 72
Test Date: 2025-05-01 10:10:14 Functions: 100.0 % 6 6

            Line data    Source code
       1              : /* File: data_visible_classifier_iterator.c; Copyright and License: see below */
       2              : 
       3              : #include "storage/data_visible_classifier_iterator.h"
       4              : #include "u8/u8_trace.h"
       5              : #include "u8/u8_log.h"
       6              : #include "utf8stringbuf/utf8stringbuf.h"
       7              : #include <sqlite3.h>
       8              : #include <assert.h>
       9              : #include <stdint.h>
      10              : 
      11              : /*!
      12              :  *  \brief predefined search statement to find visible classifiers by diagram-id
      13              :  */
      14              : const char *const DATA_VISIBLE_CLASSIFIER_ITERATOR_SELECT_BY_DIAGRAM_ID =
      15              :     "SELECT classifiers.id,classifiers.main_type,classifiers.stereotype,"
      16              :     "classifiers.name,classifiers.description,classifiers.x_order,classifiers.y_order,classifiers.list_order,"
      17              :     "classifiers.uuid,"
      18              :     "diagramelements.id,diagramelements.diagram_id,diagramelements.display_flags,diagramelements.focused_feature_id,"
      19              :     "diagramelements.uuid "
      20              :     "FROM classifiers "
      21              :     "INNER JOIN diagramelements ON diagramelements.classifier_id=classifiers.id "
      22              :     "WHERE diagramelements.diagram_id=? "
      23              :     "ORDER BY diagramelements.id ASC;";
      24              :     /* To ensure reporducible results of json esports, ordering by a unique key is required here. */
      25              :     /* Ordering by 2 keys did not produce the expected results with sqlite3 3.34.1 */
      26              :     /* "ORDER BY classifiers.list_order ASC,diagramelements.id ASC;"; */
      27              :     /* see also https://sqlite.org/forum/forumpost/e1033dab18c262ac4b36cdf7c65bf87a5aaaecab3b3ba100e4588fc30e50f9fb */
      28              : 
      29              : /*!
      30              :  *  \brief the column id of the result where this parameter is stored: id
      31              :  */
      32              : static const int RESULT_CLASSIFIER_ID_COLUMN = 0;
      33              : 
      34              : /*!
      35              :  *  \brief the column id of the result where this parameter is stored: main_type
      36              :  */
      37              : static const int RESULT_CLASSIFIER_MAIN_TYPE_COLUMN = 1;
      38              : 
      39              : /*!
      40              :  *  \brief the column id of the result where this parameter is stored: stereotype
      41              :  */
      42              : static const int RESULT_CLASSIFIER_STEREOTYPE_COLUMN = 2;
      43              : 
      44              : /*!
      45              :  *  \brief the column id of the result where this parameter is stored: name
      46              :  */
      47              : static const int RESULT_CLASSIFIER_NAME_COLUMN = 3;
      48              : 
      49              : /*!
      50              :  *  \brief the column id of the result where this parameter is stored: description
      51              :  */
      52              : static const int RESULT_CLASSIFIER_DESCRIPTION_COLUMN = 4;
      53              : 
      54              : /*!
      55              :  *  \brief the column id of the result where this parameter is stored: x_order
      56              :  */
      57              : static const int RESULT_CLASSIFIER_X_ORDER_COLUMN = 5;
      58              : 
      59              : /*!
      60              :  *  \brief the column id of the result where this parameter is stored: y_order
      61              :  */
      62              : static const int RESULT_CLASSIFIER_Y_ORDER_COLUMN = 6;
      63              : 
      64              : /*!
      65              :  *  \brief the column id of the result where this parameter is stored: list_order
      66              :  */
      67              : static const int RESULT_CLASSIFIER_LIST_ORDER_COLUMN = 7;
      68              : 
      69              : /*!
      70              :  *  \brief the column id of the result where this parameter is stored: uuid
      71              :  */
      72              : static const int RESULT_CLASSIFIER_UUID_COLUMN = 8;
      73              : 
      74              : /*!
      75              :  *  \brief the column id of the result where this parameter is stored: diagramelements.id
      76              :  */
      77              : static const int RESULT_DIAGRAMELEMENT_ID_COLUMN = 9;
      78              : 
      79              : /*!
      80              :  *  \brief the column id of the result where this parameter is stored: diagramelements.diagram_id
      81              :  */
      82              : static const int RESULT_DIAGRAMELEMENT_DIAGRAM_ID_COLUMN = 10;
      83              : 
      84              : /*!
      85              :  *  \brief the column id of the result where this parameter is stored: diagramelements.display_flags
      86              :  */
      87              : static const int RESULT_DIAGRAMELEMENT_DISPLAY_FLAGS_COLUMN = 11;
      88              : 
      89              : /*!
      90              :  *  \brief the column id of the result where this parameter is stored: diagramelements.focused_feature_id
      91              :  */
      92              : static const int RESULT_DIAGRAMELEMENT_FOCUSED_FEATURE_ID_COLUMN = 12;
      93              : 
      94              : /*!
      95              :  *  \brief the column id of the result where this parameter is stored: diagramelements.uuid
      96              :  */
      97              : static const int RESULT_DIAGRAMELEMENT_UUID_COLUMN = 13;
      98              : 
      99           12 : u8_error_t data_visible_classifier_iterator_init_empty ( data_visible_classifier_iterator_t *this_ )
     100              : {
     101           12 :     U8_TRACE_BEGIN();
     102           12 :     u8_error_t result = U8_ERROR_NONE;
     103              : 
     104           12 :     data_database_borrowed_stmt_init_void( &((*this_).statement) );
     105           12 :     (*this_).is_at_end = true;
     106              : 
     107           12 :     U8_TRACE_END_ERR(result);
     108           12 :     return result;
     109              : }
     110              : 
     111           12 : u8_error_t data_visible_classifier_iterator_reinit ( data_visible_classifier_iterator_t *this_,
     112              :                                              data_database_borrowed_stmt_t statement )
     113              : {
     114           12 :     U8_TRACE_BEGIN();
     115           12 :     assert( data_database_borrowed_stmt_is_valid( &statement ) );
     116           12 :     u8_error_t result = U8_ERROR_NONE;
     117              : 
     118              :     /* destroy old state */
     119           12 :     result = data_visible_classifier_iterator_destroy( this_ );
     120              : 
     121              :     /* init new state */
     122           12 :     (*this_).statement = statement;
     123           12 :     (*this_).is_at_end = false;
     124           12 :     result |= data_visible_classifier_iterator_private_step_to_next( this_ );
     125              : 
     126           12 :     U8_TRACE_END_ERR(result);
     127           12 :     return result;
     128              : }
     129              : 
     130           24 : u8_error_t data_visible_classifier_iterator_destroy ( data_visible_classifier_iterator_t *this_ )
     131              : {
     132           24 :     U8_TRACE_BEGIN();
     133           24 :     u8_error_t result = U8_ERROR_NONE;
     134              : 
     135           24 :     result |= data_database_borrowed_stmt_destroy( &((*this_).statement) );
     136           24 :     (*this_).is_at_end = true;
     137              : 
     138           24 :     U8_TRACE_END_ERR(result);
     139           24 :     return result;
     140              : }
     141              : 
     142          200 : bool data_visible_classifier_iterator_has_next ( const data_visible_classifier_iterator_t *this_ )
     143              : {
     144          200 :     return ( ! (*this_).is_at_end );
     145              : }
     146              : 
     147          192 : u8_error_t data_visible_classifier_iterator_next ( data_visible_classifier_iterator_t *this_, data_visible_classifier_t *out_visible_classifier )
     148              : {
     149          192 :     U8_TRACE_BEGIN();
     150          192 :     assert( NULL != out_visible_classifier );
     151          192 :     assert( data_database_borrowed_stmt_is_valid( &((*this_).statement) ) );
     152          192 :     u8_error_t result = U8_ERROR_NONE;
     153              : 
     154          192 :     if ( ! (*this_).is_at_end )
     155              :     {
     156          191 :         sqlite3_stmt *const sql_statement = data_database_borrowed_stmt_get_statement( &((*this_).statement) );
     157              : 
     158          191 :         data_visible_classifier_init_empty( out_visible_classifier );
     159              : 
     160              :         data_classifier_t *current_classifier;
     161          191 :         current_classifier = data_visible_classifier_get_classifier_ptr( out_visible_classifier );
     162          191 :         data_row_t classifier_id = sqlite3_column_int64( sql_statement, RESULT_CLASSIFIER_ID_COLUMN );
     163          382 :         result |= data_classifier_reinit( current_classifier,
     164              :                                           classifier_id,
     165          191 :                                           sqlite3_column_int( sql_statement, RESULT_CLASSIFIER_MAIN_TYPE_COLUMN ),
     166          191 :                                           (const char*) sqlite3_column_text( sql_statement, RESULT_CLASSIFIER_STEREOTYPE_COLUMN ),
     167          191 :                                           (const char*) sqlite3_column_text( sql_statement, RESULT_CLASSIFIER_NAME_COLUMN ),
     168          191 :                                           (const char*) sqlite3_column_text( sql_statement, RESULT_CLASSIFIER_DESCRIPTION_COLUMN ),
     169              :                                           sqlite3_column_int( sql_statement, RESULT_CLASSIFIER_X_ORDER_COLUMN ),
     170              :                                           sqlite3_column_int( sql_statement, RESULT_CLASSIFIER_Y_ORDER_COLUMN ),
     171              :                                           sqlite3_column_int( sql_statement, RESULT_CLASSIFIER_LIST_ORDER_COLUMN ),
     172          191 :                                           (const char*) sqlite3_column_text( sql_statement, RESULT_CLASSIFIER_UUID_COLUMN )
     173              :                                         );
     174              : 
     175              :         data_diagramelement_t *current_diag_element;
     176          191 :         current_diag_element = data_visible_classifier_get_diagramelement_ptr( out_visible_classifier );
     177          191 :         result |= data_diagramelement_reinit( current_diag_element,
     178          191 :                                               sqlite3_column_int64( sql_statement, RESULT_DIAGRAMELEMENT_ID_COLUMN ),
     179          191 :                                               sqlite3_column_int64( sql_statement, RESULT_DIAGRAMELEMENT_DIAGRAM_ID_COLUMN ),
     180              :                                               classifier_id,
     181          191 :                                               sqlite3_column_int64( sql_statement, RESULT_DIAGRAMELEMENT_DISPLAY_FLAGS_COLUMN ),
     182          191 :                                               sqlite3_column_int64( sql_statement, RESULT_DIAGRAMELEMENT_FOCUSED_FEATURE_ID_COLUMN ),
     183          191 :                                               (const char*) sqlite3_column_text( sql_statement, RESULT_DIAGRAMELEMENT_UUID_COLUMN )
     184              :                                             );
     185          191 :         if ( SQLITE_NULL == sqlite3_column_type( sql_statement, RESULT_DIAGRAMELEMENT_FOCUSED_FEATURE_ID_COLUMN ) )
     186              :         {
     187          188 :             data_diagramelement_set_focused_feature_row_id ( current_diag_element, DATA_ROW_VOID );
     188              :         }
     189              : 
     190          191 :         data_classifier_trace( current_classifier );
     191          191 :         data_diagramelement_trace( current_diag_element );
     192              : 
     193              :         /* step to next */
     194          191 :         result |= data_visible_classifier_iterator_private_step_to_next( this_ );
     195              :     }
     196              :     else
     197              :     {
     198            1 :         U8_TRACE_INFO( "iterator already at end" );
     199            1 :         (*this_).is_at_end = true;
     200            1 :         result |= U8_ERROR_INVALID_REQUEST;
     201              :     }
     202              : 
     203          192 :     U8_TRACE_END_ERR( result );
     204          192 :     return result;
     205              : }
     206              : 
     207          203 : u8_error_t data_visible_classifier_iterator_private_step_to_next ( data_visible_classifier_iterator_t *this_ )
     208              : {
     209          203 :     U8_TRACE_BEGIN();
     210          203 :     assert( data_database_borrowed_stmt_is_valid( &((*this_).statement) ) );
     211          203 :     u8_error_t result = U8_ERROR_NONE;
     212              : 
     213              :     /* do one step, check if is_at_end */
     214              :     {
     215              :         int sqlite_err;
     216          203 :         U8_TRACE_INFO( "sqlite3_step()" );
     217          203 :         sqlite_err = sqlite3_step( data_database_borrowed_stmt_get_statement( &((*this_).statement) ) );
     218          203 :         if ( SQLITE_DONE == sqlite_err )
     219              :         {
     220           11 :             U8_TRACE_INFO( "sqlite3_step finished: SQLITE_DONE" );
     221           11 :             (*this_).is_at_end = true;
     222              :         }
     223          192 :         else if ( SQLITE_ROW == sqlite_err )
     224              :         {
     225          192 :             (*this_).is_at_end = false;
     226              :         }
     227              :         else
     228              :         {
     229            0 :             U8_LOG_ERROR_INT( "sqlite3_step failed:", sqlite_err );
     230            0 :             (*this_).is_at_end = true;
     231            0 :             result |= data_visible_classifier_iterator_destroy( this_ );
     232            0 :             result |= U8_ERROR_AT_DB;
     233              :         }
     234              :     }
     235              : 
     236          203 :     U8_TRACE_END_ERR(result);
     237          203 :     return result;
     238              : }
     239              : 
     240              : 
     241              : /*
     242              : Copyright 2024-2025 Andreas Warnke
     243              : 
     244              : Licensed under the Apache License, Version 2.0 (the "License");
     245              : you may not use this file except in compliance with the License.
     246              : You may obtain a copy of the License at
     247              : 
     248              :     http://www.apache.org/licenses/LICENSE-2.0
     249              : 
     250              : Unless required by applicable law or agreed to in writing, software
     251              : distributed under the License is distributed on an "AS IS" BASIS,
     252              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     253              : See the License for the specific language governing permissions and
     254              : limitations under the License.
     255              : */
        

Generated by: LCOV version 2.0-1