@@ -255,6 +255,28 @@ uint32_t derive_col_type_or_len(int type, const void *val, int len) {
255255 return col_type_or_len ;
256256}
257257
258+ // Returns one of the four types based on column type or len
259+ // found in header
260+ // See https://www.sqlite.org/fileformat.html#record_format
261+ uint32_t derive_col_type (int hdr_col_type_or_len ) {
262+ switch (hdr_col_type_or_len ) {
263+ case 7 :
264+ return DBLOG_TYPE_REAL ;
265+ case 1 :
266+ case 2 :
267+ case 3 :
268+ case 4 :
269+ case 5 :
270+ case 6 :
271+ case 8 :
272+ case 9 :
273+ return DBLOG_TYPE_INT ;
274+ default :
275+ return (hdr_col_type_or_len % 2 ? DBLOG_TYPE_TEXT : DBLOG_TYPE_BLOB );
276+ }
277+ return DBLOG_TYPE_TEXT ; // error
278+ }
279+
258280byte c1 , c2 , c3 ;
259281void saveChecksumBytes (byte * ptr , uint16_t last_pos ) {
260282 ptr += last_pos ;
@@ -1472,3 +1494,27 @@ int dblog_bin_srch_row_by_val(struct dblog_read_context *rctx, int col_idx,
14721494 rctx -> cur_rec_pos = size ;
14731495 return DBLOG_RES_OK ;
14741496}
1497+
1498+ // See .h file for API description
1499+ int dblog_upd_col_val (struct dblog_read_context * rctx , int col_idx , const void * val ) {
1500+ uint8_t * buf = rctx -> buf ;
1501+ if (buf [0 ] != 13 )
1502+ return DBLOG_RES_ERR ;
1503+ int16_t rec_count = read_uint16 (rctx -> buf + 3 );
1504+ if (rec_count <= rctx -> cur_rec_pos )
1505+ return DBLOG_RES_ERR ;
1506+ uint32_t u32_at ;
1507+ byte * val_at = read_val_at (rctx , rctx -> cur_rec_pos , col_idx , & u32_at , 0 );
1508+ if (!val_at )
1509+ return DBLOG_RES_NOT_FOUND ;
1510+ int len = dblog_derive_data_len (u32_at );
1511+ write_data (val_at , derive_col_type (u32_at ), val , len );
1512+ return DBLOG_RES_OK ;
1513+ }
1514+
1515+ int dblog_write_cur_page (struct dblog_read_context * rctx , write_fn_def write_fn ) {
1516+ struct dblog_write_context wctx ;
1517+ wctx .buf = rctx -> buf ;
1518+ wctx .write_fn = write_fn ;
1519+ return write_page (& wctx , rctx -> cur_page , get_pagesize (rctx -> page_size_exp ));
1520+ }
0 commit comments