this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix database query

+48 -9
+4 -4
src/core/types.odin
··· 21 21 } 22 22 23 23 Album :: struct { 24 - id: string `sqlite:"id"`, 25 - title: string `sqlite:"title"`, 26 - mb_id: Maybe(string) `sqlite:"mb_id"`, // MUSICBRAINZ_ALBUMID, 27 - mb_rg_id: Maybe(string) `sqlite:"mb_rg_id"`, // MUSICBRAINZ_RELEASEGROUPID, 24 + id: Album_Id, 25 + title: string, 26 + mb_id: Maybe(string), // MUSICBRAINZ_ALBUMID, 27 + mb_rg_id: Maybe(string), // MUSICBRAINZ_RELEASEGROUPID, 28 28 } 29 29 30 30
+43 -5
src/db/repo/album.odin
··· 4 4 import sqlite "../../../vendor/sqlite" 5 5 import sa "../../../vendor/sqlite/addons" 6 6 import types "../../core" 7 + import "core:c" 7 8 import "core:fmt" 9 + import "core:strings" 8 10 9 11 new_album :: proc( 10 12 db: ^sqlite.Connection, ··· 77 79 ok: bool, 78 80 ) { 79 81 80 - params := []sa.Query_Param{{1, id}} 81 - query := "SELECT * FROM album WHERE id = ? LIMIT 1" 82 + query: cstring = "SELECT * FROM album WHERE id = ? LIMIT 1" 82 83 83 - albums := make([dynamic]types.Album, 0, 1) 84 + stmt: ^sqlite.Statement 84 85 85 - rc := sa.query(db, &albums, query, params) 86 - if (rc != .Ok || len(albums) != 1) { 86 + if rc := sqlite.prepare_v2(db, query, c.int(len(query)), &stmt, nil); rc != .Ok { 87 + fmt.eprintfln("failed to prepare statement. result code: {}", rc) 87 88 return res, false 89 + } 90 + 91 + defer sqlite.finalize(stmt) 92 + 93 + c_id := strings.clone_to_cstring(id, allocator) 94 + defer delete(c_id) 95 + 96 + if rc := sqlite.bind_text( 97 + stmt, 98 + param_idx = 1, 99 + param_value = c_id, 100 + param_len = c.int(len(id)), 101 + free = {behaviour = .Static}, 102 + ); rc != .Ok { 103 + fmt.eprintfln("failed to bind value to ArtistId. result code: {}", rc) 104 + return res, false 105 + } 106 + 107 + fmt.printfln("prepared sql: {}\n", sqlite.expanded_sql(stmt)) 108 + 109 + albums := make([dynamic]types.Album, 0, 1) 110 + defer { 111 + for album in albums { 112 + delete(string(album.id)) 113 + delete(album.title) 114 + } 115 + delete_dynamic_array(albums) 116 + } 117 + 118 + for sqlite.step(stmt) == .Row { 119 + 120 + album := types.Album { 121 + id = types.Album_Id(strings.clone_from(sqlite.column_text(stmt, 0))), 122 + title = strings.clone_from(sqlite.column_text(stmt, 1)), 123 + } 124 + 125 + append(&albums, album) 88 126 } 89 127 90 128 return albums[0], true
+1
src/db/repo/album.test.odin
··· 101 101 testing.expect(t, ok) 102 102 testing.expect(t, album.title == "Test title") 103 103 104 + fmt.printfln("Album: %#v", album) 104 105 }