Skip to content

Support OUT parameters (sql.Out) for stored procedures #220

@cole-maxwell1

Description

@cole-maxwell1

Hi! First, thank you for maintaining this project!

I’m using github.com/alexbrainman/odbc to call a stored procedure on DB2 for i (IBMi / iSeries / AS400) via the IBM i Access ODBC driver. The procedure has several OUT parameters. When I pass sql.Out arguments to ExecContext, I get:

sql: converting argument with name "MyVarName" type: unsupported type sql.Out, a struct

This appears to happen in the database/sql layer when the driver does not handle sql.Out via NamedValueChecker.

Minimal reproducible example

Server (DB2 for i): small repro procedure with one IN and one OUT param.

-- Schema: QGPL (or any test schema)
CREATE OR REPLACE PROCEDURE QGPL.OUT1(
  IN  P_IN  DECIMAL(5,0),
  OUT P_OUT DECIMAL(5,0)
)
LANGUAGE SQL
BEGIN
  SET P_OUT = P_IN + 1;
END

Client (Go):

package main

import (
	"context"
	"database/sql"
	"fmt"
	"log"

	_ "github.com/alexbrainman/odbc"
)

func main() {
	// Example DSN; replace with your own
	// IBM i Access ODBC driver
	dsn := "DSN=MY_IBMI_DSN" // e.g., SYSTEM=ibmi.local;UID=xxxx;PWD=xxxx;...

	db, err := sql.Open("odbc", dsn)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	ctx := context.Background()

	var out int64
	// ODBC call escape syntax
	const call = `{CALL QGPL.OUT1(?, ?)}`
	_, err = db.ExecContext(ctx, call,
		41,
		sql.Named("P_OUT", sql.Out{Dest: &out}),
	)
	if err != nil {
		// Actual output:
		// sql: converting argument with name "P_OUT" type: unsupported type sql.Out, a struct
		log.Fatalf("exec failed: %v", err)
	}

	fmt.Println("OUT value:", out)
}

Actual result:

exec failed: sql: converting argument with name "P_OUT" type: unsupported type sql.Out, a struct

Expected result:

ExecContext succeeds.

The driver binds P_OUT as an output parameter (ODBC SQL_PARAM_OUTPUT or SQL_PARAM_INPUT_OUTPUT), executes the procedure, and writes the returned value into out.

Request

Would you consider adding support for sql.Out OUT parameters? Concretely, implementing driver.NamedValueChecker (or otherwise handling sql.Out) so that OUT and INOUT params are accepted by ExecContext / QueryContext.

Environment

  • Go version: 1.25.1
  • OS/Arch: Linux x86_64
  • alexbrainman/odbc version: v0.0.0-20250601004241-49e6b2bc0cf0
  • ODBC driver: IBM i Access ODBC Driver
  • Database: DB2 for i 7.4 (IBMi / iSeries / AS400)

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