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.6 % 31 25
Test Date: 2026-03-31 13:51:38 Functions: 100.0 % 1 1
Branches: 71.4 % 14 10

             Branch data     Line data    Source code
       1                 :             : #include "precizer.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Read file data from the database into file->db
       5                 :             :  *
       6                 :             :  * Loads the saved row for @p relative_path into the DBrow attached to @p file.
       7                 :             :  * If the path is missing in the database, the attached row stays zeroed and
       8                 :             :  * relative_path_was_in_db_before_processing remains false
       9                 :             :  *
      10                 :             :  * @param[in,out] file Per-file state whose attached DB row receives the loaded values
      11                 :             :  * @param[in] relative_path Relative path looked up in the files table
      12                 :             :  */
      13                 :        3348 : Return db_read_file_data_from(
      14                 :             :         File *file,
      15                 :             : #if 0 // Old multiPATH solution
      16                 :             :         const sqlite3_int64 *path_prefix_index,
      17                 :             : #endif
      18                 :             :         const char *relative_path)
      19                 :             : {
      20                 :             :         /* Status returned by this function through provide()
      21                 :             :            Default value assumes successful completion */
      22                 :        3348 :         Return status = SUCCESS;
      23                 :             : 
      24                 :             :         /* Read from SQL */
      25                 :        3348 :         sqlite3_stmt *select_stmt = NULL;
      26                 :             :         int rc;
      27                 :             :         // Convenience alias for the attached DB row that receives the loaded values
      28                 :        3348 :         DBrow *dbrow = file->db;
      29                 :             : 
      30                 :             :         /* Create SQL statement */
      31                 :             : #if 0 // Old multiPATH solution
      32                 :             :         const char *select_sql = "SELECT ID,offset,stat,mdContext,sha512 FROM files WHERE path_prefix_index = ?1 and relative_path = ?2;";
      33                 :             : #else
      34                 :        3348 :         const char *select_sql = "SELECT ID,offset,stat,mdContext,sha512 FROM files WHERE relative_path = ?1;";
      35                 :             : #endif
      36                 :        3348 :         rc = sqlite3_prepare_v2(config->db,select_sql,-1,&select_stmt,NULL);
      37                 :             : 
      38         [ -  + ]:        3348 :         if(SQLITE_OK != rc)
      39                 :             :         {
      40                 :           0 :                 log_sqlite_error(config->db,rc,NULL,"Can't prepare select statement %s",select_sql);
      41                 :           0 :                 status = FAILURE;
      42                 :             :         }
      43                 :             : 
      44                 :             : #if 0 // Old multiPATH solution
      45                 :             :         rc = sqlite3_bind_int64(select_stmt,1,*path_prefix_index);
      46                 :             : 
      47                 :             :         if(SQLITE_OK != rc)
      48                 :             :         {
      49                 :             :                 log_sqlite_error(config->db,rc,NULL,"Error binding value in select");
      50                 :             :                 status = FAILURE;
      51                 :             :         }
      52                 :             : #endif
      53                 :        3348 :         rc = sqlite3_bind_text(select_stmt,1,relative_path,(int)strlen(relative_path),NULL);
      54                 :             : 
      55         [ -  + ]:        3348 :         if(SQLITE_OK != rc)
      56                 :             :         {
      57                 :           0 :                 log_sqlite_error(config->db,rc,NULL,"Error binding value in select");
      58                 :           0 :                 status = FAILURE;
      59                 :             :         }
      60                 :             : 
      61         [ +  + ]:        4652 :         while(SQLITE_ROW == (rc = sqlite3_step(select_stmt)))
      62                 :             :         {
      63                 :        1304 :                 dbrow->ID = sqlite3_column_int64(select_stmt,0);
      64                 :        1304 :                 dbrow->saved_offset = sqlite3_column_int64(select_stmt,1);
      65                 :        1304 :                 const CmpctStat *get_stat = sqlite3_column_blob(select_stmt,2);
      66                 :             : 
      67         [ +  - ]:        1304 :                 if(get_stat != NULL)
      68                 :             :                 {
      69                 :        1304 :                         memcpy(&dbrow->saved_stat,get_stat,sizeof(CmpctStat));
      70                 :             :                 }
      71                 :        1304 :                 const SHA512_Context *get_mdContext = sqlite3_column_blob(select_stmt,3);
      72                 :             : 
      73         [ +  + ]:        1304 :                 if(get_mdContext != NULL)
      74                 :             :                 {
      75                 :           4 :                         memcpy(&dbrow->saved_mdContext,get_mdContext,sizeof(SHA512_Context));
      76                 :             :                 }
      77                 :             : 
      78                 :        1304 :                 const unsigned char *get_sha512 = sqlite3_column_blob(select_stmt,4);
      79                 :             : 
      80         [ +  + ]:        1304 :                 if(get_sha512 != NULL)
      81                 :             :                 {
      82                 :        1294 :                         memcpy(&dbrow->sha512,get_sha512,SHA512_DIGEST_LENGTH);
      83                 :             :                 }
      84                 :             : 
      85                 :        1304 :                 dbrow->relative_path_was_in_db_before_processing = true;
      86                 :             :         }
      87                 :             : 
      88         [ -  + ]:        3348 :         if(SQLITE_DONE != rc)
      89                 :             :         {
      90                 :           0 :                 log_sqlite_error(config->db,rc,NULL,"Select statement didn't finish with DONE");
      91                 :           0 :                 status = FAILURE;
      92                 :             :         }
      93                 :        3348 :         sqlite3_finalize(select_stmt);
      94                 :             : 
      95                 :        3348 :         provide(status);
      96                 :             : }
        

Generated by: LCOV version 2.0-1