LCOV - code coverage report
Current view: top level - src - db_read_file_data_from.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.0 % 30 24
Test Date: 2026-03-01 04:31:48 Functions: 100.0 % 1 1
Branches: 71.4 % 14 10

             Branch data     Line data    Source code
       1                 :             : #include "precizer.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  *
       5                 :             :  * @brief Read data about the file from DB
       6                 :             :  *
       7                 :             :  */
       8                 :        2914 : 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                 :             :         /* Status returned by this function through provide()
      16                 :             :            Default value assumes successful completion */
      17                 :        2914 :         Return status = SUCCESS;
      18                 :             : 
      19                 :             :         /* Read from SQL */
      20                 :        2914 :         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                 :        2914 :         const char *select_sql = "SELECT ID,offset,stat,mdContext,sha512 FROM files WHERE relative_path = ?1;";
      28                 :             : #endif
      29                 :        2914 :         rc = sqlite3_prepare_v2(config->db,select_sql,-1,&select_stmt,NULL);
      30                 :             : 
      31         [ -  + ]:        2914 :         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                 :        2914 :         rc = sqlite3_bind_text(select_stmt,1,relative_path,(int)strlen(relative_path),NULL);
      47                 :             : 
      48         [ -  + ]:        2914 :         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         [ +  + ]:        4194 :         while(SQLITE_ROW == (rc = sqlite3_step(select_stmt)))
      55                 :             :         {
      56                 :        1280 :                 dbrow->ID = sqlite3_column_int64(select_stmt,0);
      57                 :        1280 :                 dbrow->saved_offset = sqlite3_column_int64(select_stmt,1);
      58                 :        1280 :                 const CmpctStat *get_stat = sqlite3_column_blob(select_stmt,2);
      59                 :             : 
      60         [ +  - ]:        1280 :                 if(get_stat != NULL)
      61                 :             :                 {
      62                 :        1280 :                         memcpy(&dbrow->saved_stat,get_stat,sizeof(CmpctStat));
      63                 :             :                 }
      64                 :        1280 :                 const SHA512_Context *get_mdContext = sqlite3_column_blob(select_stmt,3);
      65                 :             : 
      66         [ +  + ]:        1280 :                 if(get_mdContext != NULL)
      67                 :             :                 {
      68                 :           4 :                         memcpy(&dbrow->saved_mdContext,get_mdContext,sizeof(SHA512_Context));
      69                 :             :                 }
      70                 :             : 
      71                 :        1280 :                 const unsigned char *get_sha512 = sqlite3_column_blob(select_stmt,4);
      72                 :             : 
      73         [ +  + ]:        1280 :                 if(get_sha512 != NULL)
      74                 :             :                 {
      75                 :        1270 :                         memcpy(&dbrow->sha512,get_sha512,SHA512_DIGEST_LENGTH);
      76                 :             :                 }
      77                 :             : 
      78                 :        1280 :                 dbrow->relative_path_was_in_db_before_processing = true;
      79                 :             :         }
      80                 :             : 
      81         [ -  + ]:        2914 :         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                 :        2914 :         sqlite3_finalize(select_stmt);
      87                 :             : 
      88                 :        2914 :         provide(status);
      89                 :             : }
        

Generated by: LCOV version 2.0-1