| 482 | } |
| 483 | |
| 484 | static bool gd_table_header(gd_context_t *g, int index, bool present) { |
| 485 | const gd_table_t *table = &gd_tables[index]; |
| 486 | if (!gd_u8(g, 0x20) || !gd_u32(g, (uint32_t)index) || !gd_literal(g, table->name) || |
| 487 | !gd_u32(g, (uint32_t)table->column_count)) { |
| 488 | return false; |
| 489 | } |
| 490 | for (int i = 0; i < table->column_count; i++) { |
| 491 | const gd_column_t *column = &table->columns[i]; |
| 492 | if (!gd_literal(g, column->name) || !gd_u8(g, column->types) || !gd_u8(g, column->kind)) { |
| 493 | return false; |
| 494 | } |
| 495 | } |
| 496 | if (!gd_u8(g, present ? 1 : 0)) { |
| 497 | return false; |
| 498 | } |
| 499 | if (!present) { |
| 500 | return gd_value(g, GD_NULL, NULL, 0); |
| 501 | } |
| 502 | if (!gd_prepare(g, "SELECT name,type,sql FROM main.sqlite_schema " |
| 503 | "WHERE name=?1 COLLATE NOCASE AND type IN ('table','view');") || |
| 504 | !gd_bind_name(g, table->name)) { |
| 505 | return false; |
| 506 | } |
| 507 | if (gd_step(g) != SQLITE_ROW) { |
| 508 | return gd_fail(g, CBM_STORE_GRAPH_DIGEST_SCHEMA); |
| 509 | } |
| 510 | gd_text_t name, type, sql; |
| 511 | if (!gd_read_text(g, 0, &name) || !gd_read_text(g, 1, &type) || !gd_read_text(g, 2, &sql)) { |
| 512 | return false; |
| 513 | } |
| 514 | if (!gd_text_eq(name, table->name) || !gd_text_eq(type, "table")) { |
| 515 | return gd_fail(g, CBM_STORE_GRAPH_DIGEST_SCHEMA); |
| 516 | } |
| 517 | if (!gd_value(g, GD_TEXT, sql.data, sql.length)) { |
| 518 | return false; |
| 519 | } |
| 520 | if (gd_step(g) != SQLITE_DONE) { |
| 521 | return gd_fail(g, CBM_STORE_GRAPH_DIGEST_SCHEMA); |
| 522 | } |
| 523 | return gd_finalize(g); |
| 524 | } |
| 525 | |
| 526 | static bool gd_generation(gd_context_t *g) { |
| 527 | gd_text_t key, value; |
no test coverage detected