LCOV - code coverage report
Current view: top level - src - db_read_file_data_from.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 76.7 % 30 23
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #include "precizer.h"
       2              : 
       3              : /**
       4              :  *
       5              :  * @brief Read data about the file from DB
       6              :  *
       7              :  */
       8         1968 : Return db_read_file_data_from(
       9              :         DBrow *dbrow,
      10              : #if 0 // Old multiPATH solution
      11              :         const sqlite3_int64 *path_prefix_index,
      12              : #endif
      13              :         const char *relative_path)
      14              : {
      15              :         /// The status that will be passed to return() before exiting.
      16              :         /// By default, the function worked without errors.
      17         1968 :         Return status = SUCCESS;
      18              : 
      19              :         /* Read from SQL */
      20         1968 :         sqlite3_stmt *select_stmt = NULL;
      21              :         int rc;
      22              : 
      23              :         /* Create SQL statement */
      24              : #if 0 // Old multiPATH solution
      25              :         const char *select_sql = "SELECT ID,offset,stat,mdContext,sha512 FROM files WHERE path_prefix_index = ?1 and relative_path = ?2;";
      26              : #else
      27         1968 :         const char *select_sql = "SELECT ID,offset,stat,mdContext,sha512 FROM files WHERE relative_path = ?1;";
      28              : #endif
      29         1968 :         rc = sqlite3_prepare_v2(config->db,select_sql,-1,&select_stmt,NULL);
      30              : 
      31         1968 :         if(SQLITE_OK != rc)
      32              :         {
      33            0 :                 log_sqlite_error(config->db,rc,NULL,"Can't prepare select statement %s",select_sql);
      34            0 :                 status = FAILURE;
      35              :         }
      36              : 
      37              : #if 0 // Old multiPATH solution
      38              :         rc = sqlite3_bind_int64(select_stmt,1,*path_prefix_index);
      39              : 
      40              :         if(SQLITE_OK != rc)
      41              :         {
      42              :                 log_sqlite_error(config->db,rc,NULL,"Error binding value in select");
      43              :                 status = FAILURE;
      44              :         }
      45              : #endif
      46         1968 :         rc = sqlite3_bind_text(select_stmt,1,relative_path,(int)strlen(relative_path),NULL);
      47              : 
      48         1968 :         if(SQLITE_OK != rc)
      49              :         {
      50            0 :                 log_sqlite_error(config->db,rc,NULL,"Error binding value in select");
      51            0 :                 status = FAILURE;
      52              :         }
      53              : 
      54         2902 :         while(SQLITE_ROW == (rc = sqlite3_step(select_stmt)))
      55              :         {
      56          934 :                 dbrow->ID = sqlite3_column_int64(select_stmt,0);
      57          934 :                 dbrow->saved_offset = sqlite3_column_int64(select_stmt,1);
      58          934 :                 const CmpctStat *get_stat = sqlite3_column_blob(select_stmt,2);
      59              : 
      60          934 :                 if(get_stat != NULL)
      61              :                 {
      62          934 :                         memcpy(&dbrow->saved_stat,get_stat,sizeof(CmpctStat));
      63              :                 }
      64          934 :                 const SHA512_Context *get_mdContext = sqlite3_column_blob(select_stmt,3);
      65              : 
      66          934 :                 if(get_mdContext != NULL)
      67              :                 {
      68            0 :                         memcpy(&dbrow->saved_mdContext,get_mdContext,sizeof(SHA512_Context));
      69              :                 }
      70              : 
      71          934 :                 const unsigned char *get_sha512 = sqlite3_column_blob(select_stmt,4);
      72              : 
      73          934 :                 if(get_sha512 != NULL)
      74              :                 {
      75          928 :                         memcpy(&dbrow->sha512,get_sha512,SHA512_DIGEST_LENGTH);
      76              :                 }
      77              : 
      78          934 :                 dbrow->relative_path_already_in_db = true;
      79              :         }
      80              : 
      81         1968 :         if(SQLITE_DONE != rc)
      82              :         {
      83            0 :                 log_sqlite_error(config->db,rc,NULL,"Select statement didn't finish with DONE");
      84            0 :                 status = FAILURE;
      85              :         }
      86         1968 :         sqlite3_finalize(select_stmt);
      87              : 
      88         1968 :         provide(status);
      89              : }
        

Generated by: LCOV version 2.0-1