Skip to content

mysql: select statement with single column failed to compile and generate #1

@kohei-noda-qcrg

Description

@kohei-noda-qcrg

@lcarilla

I cannot generate PHP code with single column select statement and :one or :many sqlc query annotation.
it raises error with the following error message:

#  package php
error generating code: error generating output: template: table:79:47: executing "table" at <.Ret.ResultSet>: error calling ResultSet: runtime error: invalid memory address or nil pointer dereference

This error occurs because v.Struct.Fields is accessed with the ResultSet function when v.Struct is nil.
Should set value properly to QueryValue.Struct even if query.Colums is 1 or add IsScalar field to QueryValue struct and handle it in the query_impl template file.

  • logs to reproduce this issue
noda@arch /tmp/work $ git clone https://github.com/lcarilla/sqlc-plugin-php-dbal
Cloning into 'sqlc-plugin-php-dbal'...
remote: Enumerating objects: 734, done.
remote: Counting objects: 100% (40/40), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 734 (delta 26), reused 24 (delta 19), pack-reused 694 (from 1)
Receiving objects: 100% (734/734), 233.85 KiB | 4.18 MiB/s, done.
Resolving deltas: 100% (302/302), done.
noda@arch /tmp/work $ cd sqlc-plugin-php-dbal/
noda@arch /tmp/work/sqlc-plugin-php-dbal (main) $
noda@arch /tmp/work/sqlc-plugin-php-dbal (main) $ ls
examples  go.mod  go.sum  internal  LICENSE  Makefile  plugin  README.md  sqlc-plugin-php-dbal.iml
noda@arch /tmp/work/sqlc-plugin-php-dbal (main) $ git log --oneline | head -n1
c411b3d create release process
noda@arch /tmp/work/sqlc-plugin-php-dbal (main) $ make all && echo ok
mkdir -p bin
cd plugin && go build -o ../bin/sqlc-gen-php ./main.go
cd plugin && GOOS=wasip1 GOARCH=wasm go build -o ../bin/sqlc-gen-php.wasm main.go
ok
noda@arch /tmp/work/sqlc-plugin-php-dbal (main) $ vi examples/symfony-example/sqlc.yaml
noda@arch /tmp/work/sqlc-plugin-php-dbal (main *) $ git diff
diff --git a/examples/symfony-example/sqlc.yaml b/examples/symfony-example/sqlc.yaml
index 1506837..d461e92 100644
--- a/examples/symfony-example/sqlc.yaml
+++ b/examples/symfony-example/sqlc.yaml
@@ -2,7 +2,7 @@ version: '2'
 plugins:
 - name: php
   wasm:
-    url: file:///Users/luis.carilla/sqlc-plugin-php-dbal/bin/sqlc-gen-kotlin.wasm
+    url: file:///tmp/work/sqlc-plugin-php-dbal/bin/sqlc-gen-php.wasm
 sql:
 - schema: sqlc/authors/mysql/schema.sql
   queries: sqlc/authors/mysql/query.sql
noda@arch /tmp/work/sqlc-plugin-php-dbal (main *) $ cd examples/symfony-example/
noda@arch /tmp/work/sqlc-plugin-php-dbal/examples/symfony-example (main *) $ sqlc version
v1.30.0
noda@arch /tmp/work/sqlc-plugin-php-dbal/examples/symfony-example (main *) $ sqlc compile
2026/01/29 16:40:56 WARN fetching WASM binary to calculate sha256. Set this value in sqlc.yaml to prevent unneeded work sha256=64fd33558fe8be098c1340e8d0d3a7da3c2d7648726708aaa0776a7abba0ce66
noda@arch /tmp/work/sqlc-plugin-php-dbal/examples/symfony-example (main *) $ echo $?
0
noda@arch /tmp/work/sqlc-plugin-php-dbal/examples/symfony-example (main *) $ vi sqlc/authors/mysql/query.sql
noda@arch /tmp/work/sqlc-plugin-php-dbal/examples/symfony-example (main *) $ git diff
diff --git a/examples/symfony-example/sqlc.yaml b/examples/symfony-example/sqlc.yaml
index 1506837..d461e92 100644
--- a/examples/symfony-example/sqlc.yaml
+++ b/examples/symfony-example/sqlc.yaml
@@ -2,7 +2,7 @@ version: '2'
 plugins:
 - name: php
   wasm:
-    url: file:///Users/luis.carilla/sqlc-plugin-php-dbal/bin/sqlc-gen-kotlin.wasm
+    url: file:///tmp/work/sqlc-plugin-php-dbal/bin/sqlc-gen-php.wasm
 sql:
 - schema: sqlc/authors/mysql/schema.sql
   queries: sqlc/authors/mysql/query.sql
diff --git a/examples/symfony-example/sqlc/authors/mysql/query.sql b/examples/symfony-example/sqlc/authors/mysql/query.sql
index c590068..6cbc430 100644
--- a/examples/symfony-example/sqlc/authors/mysql/query.sql
+++ b/examples/symfony-example/sqlc/authors/mysql/query.sql
@@ -14,6 +14,13 @@ WHERE book_id = ?;
 SELECT * FROM book
 WHERE title = UUID_TO_BIN(?) AND yr = ?;

+/* name: bookIDsByTags :many */
+SELECT
+    book_id
+FROM book
+         LEFT JOIN author ON book.author_id = author.author_id
+WHERE tags = ?;
+
 /* name: bookByTags :many */
 SELECT
     book_id,
noda@arch /tmp/work/sqlc-plugin-php-dbal/examples/symfony-example (main *) $ sqlc compile
2026/01/29 16:42:19 WARN fetching WASM binary to calculate sha256. Set this value in sqlc.yaml to prevent unneeded work sha256=64fd33558fe8be098c1340e8d0d3a7da3c2d7648726708aaa0776a7abba0ce66
# package php
error generating code: error generating output: template: table:79:47: executing "table" at <.Ret.ResultSet>: error calling ResultSet: runtime error: invalid memory address or nil pointer dereference
noda@arch /tmp/work/sqlc-plugin-php-dbal/examples/symfony-example (main *) $ echo $?
1
noda@arch /tmp/work/sqlc-plugin-php-dbal/examples/symfony-example (main *) $

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions