Skip to content

Commit 3922a0e

Browse files
committed
Fix cqual issues
1 parent 042c605 commit 3922a0e

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/btree_handler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class btree_handler {
150150
return current_block;
151151
}
152152

153-
std::string get_string(std::string key, std::string not_found_value) {
153+
std::string get_string(std::string& key, std::string& not_found_value) {
154154
bool ret = get(key.c_str(), key.length(), NULL, NULL);
155155
if (ret) {
156156
uint8_t *val = (uint8_t *) malloc(key_at_len);
@@ -205,7 +205,7 @@ class btree_handler {
205205
return descendant->search_current_block(ctx);
206206
}
207207

208-
bool put_string(std::string key, std::string value) {
208+
bool put_string(std::string& key, std::string& value) {
209209
return put(key.c_str(), key.length(), value.c_str(), value.length());
210210
}
211211
bool put(const char *key, int key_len, const char *value,

src/sqlite_index_blaster.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class sqlite_index_blaster : public btree_handler<sqlite_index_blaster> {
210210

211211
// Writes data into buffer to form first page of Sqlite db
212212
int write_page0(int total_col_count, int pk_col_count,
213-
std::string col_names, std::string table_name = {}) {
213+
const std::string& col_names, const std::string& table_name = {}) {
214214

215215
if (block_size % 512 || block_size < 512 || block_size > 65536)
216216
throw SQLT_RES_INV_PAGE_SZ;
@@ -256,9 +256,9 @@ class sqlite_index_blaster : public btree_handler<sqlite_index_blaster> {
256256
init_bt_tbl_leaf(current_block + 100);
257257

258258
// write table script record
259-
std::string default_table_name = "idx1";
260-
if (table_name.empty())
261-
table_name = default_table_name;
259+
std::string tbl_name = "idx1";
260+
if (!table_name.empty())
261+
tbl_name = table_name;
262262
// write table script record
263263
int col_count = 5;
264264
// if (table_script) {
@@ -267,7 +267,7 @@ class sqlite_index_blaster : public btree_handler<sqlite_index_blaster> {
267267
// return SQLT_RES_TOO_LONG;
268268
// set_col_val(4, SQLT_TYPE_TEXT, table_script, script_len);
269269
// } else {
270-
int table_name_len = table_name.length();
270+
int table_name_len = tbl_name.length();
271271
// len("CREATE TABLE ") + table_name_len + len(" (")
272272
// + len("PRIMARY KEY (") + len(") WITHOUT ROWID")
273273
size_t script_len = 13 + table_name_len + 2 + 13 + 15;
@@ -289,13 +289,13 @@ class sqlite_index_blaster : public btree_handler<sqlite_index_blaster> {
289289
// 100 byte header, 2 byte ptr, 3 byte rec/hdr vlen, 1 byte rowid
290290
// 6 byte hdr len, 5 byte "table", twice table name, 4 byte uint32 root
291291
if (script_len > (block_size - 100 - page_resv_bytes - blk_hdr_len
292-
- 2 - 3 - 1 - 6 - 5 - table_name.length() * 2 - 4))
292+
- 2 - 3 - 1 - 6 - 5 - tbl_name.length() * 2 - 4))
293293
return SQLT_RES_TOO_LONG;
294294
uint8_t *script_loc = current_block + block_size - page_resv_bytes - script_len;
295295
uint8_t *script_pos = script_loc;
296296
memcpy(script_pos, "CREATE TABLE ", 13);
297297
script_pos += 13;
298-
memcpy(script_pos, table_name.c_str(), table_name_len);
298+
memcpy(script_pos, tbl_name.c_str(), table_name_len);
299299
script_pos += table_name_len;
300300
*script_pos++ = ' ';
301301
*script_pos++ = '(';
@@ -312,7 +312,7 @@ class sqlite_index_blaster : public btree_handler<sqlite_index_blaster> {
312312
script_pos += 15;
313313
// }
314314
int32_t root_page_no = 2;
315-
const void *master_rec_values[] = {"table", table_name.c_str(), table_name.c_str(), &root_page_no, script_loc};
315+
const void *master_rec_values[] = {"table", tbl_name.c_str(), tbl_name.c_str(), &root_page_no, script_loc};
316316
const size_t master_rec_col_lens[] = {5, table_name.length(), table_name.length(), sizeof(root_page_no), script_len};
317317
const uint8_t master_rec_col_types[] = {SQLT_TYPE_TEXT, SQLT_TYPE_TEXT, SQLT_TYPE_TEXT, SQLT_TYPE_INT32, SQLT_TYPE_TEXT};
318318
int res = write_new_rec(0, 1, 5, master_rec_values, master_rec_col_lens, master_rec_col_types);
@@ -507,11 +507,11 @@ class sqlite_index_blaster : public btree_handler<sqlite_index_blaster> {
507507
unsigned long child_addr;
508508
int pk_count;
509509
int column_count;
510-
std::string column_names;
511-
std::string table_name;
510+
const std::string column_names;
511+
const std::string table_name;
512512
int blk_hdr_len;
513513
sqlite_index_blaster(int total_col_count, int pk_col_count,
514-
std::string col_names, std::string tbl_name = NULL,
514+
const std::string& col_names, const std::string& tbl_name = {},
515515
int block_sz = BPT_DEFAULT_BLOCK_SIZE, int cache_sz = 0,
516516
const char *fname = NULL) : column_count (total_col_count), pk_count (pk_col_count),
517517
column_names (col_names), table_name (tbl_name),

test_sqlite_blaster.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ void check_value(const char *key, int key_len, const char *val, int val_len,
315315
}
316316
}
317317

318-
string census_col_names = "cum_prop100k, rank, name, year, count, prop100k, pctwhite, pctblack, pctapi, pctaian, pct2prace, pcthispanic";
319-
const void *census_col_values[12];
318+
const string census_col_names = "cum_prop100k, rank, name, year, count, prop100k, pctwhite, pctblack, pctapi, pctaian, pct2prace, pcthispanic";
320319
const uint8_t census_col_types[] = {SQLT_TYPE_REAL, SQLT_TYPE_INT32, SQLT_TYPE_TEXT, SQLT_TYPE_INT32, SQLT_TYPE_INT32, SQLT_TYPE_REAL,
321320
SQLT_TYPE_REAL, SQLT_TYPE_REAL, SQLT_TYPE_REAL, SQLT_TYPE_REAL, SQLT_TYPE_REAL, SQLT_TYPE_REAL};
322321

@@ -391,6 +390,7 @@ bool test_census(int page_size, int cache_size, const char *filename) {
391390
pcthispanic = 0;
392391
//cout << endl;
393392
uint8_t rec[line.length() + 500];
393+
const void *census_col_values[12];
394394
census_col_values[0] = &cum_prop100k;
395395
census_col_values[1] = &rank;
396396
census_col_values[2] = (const void *) name.c_str();
@@ -443,9 +443,8 @@ bool test_census() {
443443
return true;
444444
}
445445

446-
string baby_col_names = "year, state, name, total_babies, primary_sex, primary_sex_ratio, per_100k_in_state";
446+
const string baby_col_names = "year, state, name, total_babies, primary_sex, primary_sex_ratio, per_100k_in_state";
447447
const uint8_t baby_col_types[] = {SQLT_TYPE_INT32, SQLT_TYPE_TEXT, SQLT_TYPE_TEXT, SQLT_TYPE_INT32, SQLT_TYPE_TEXT, SQLT_TYPE_REAL, SQLT_TYPE_REAL};
448-
const void *baby_col_values[7];
449448

450449
bool test_babynames(int page_size, int cache_size, const char *filename) {
451450

@@ -499,6 +498,7 @@ bool test_babynames(int page_size, int cache_size, const char *filename) {
499498
per_100k_in_state = 0;
500499
//cout << endl;
501500
uint8_t rec[line.length() + 100];
501+
const void *baby_col_values[7];
502502
baby_col_values[0] = &year;
503503
baby_col_values[1] = (const void *) state.c_str();
504504
baby_col_values[2] = (const void *) name.c_str();
@@ -545,7 +545,7 @@ bool test_babynames() {
545545
return true;
546546
}
547547

548-
string const_kv = "key, value";
548+
const string const_kv = "key, value";
549549

550550
bool test_random_data(int page_size, long start_count, int cache_size, char *filename) {
551551
unlink(filename);

0 commit comments

Comments
 (0)