<commit_before>package jdbi.doc;

import static org.assertj.core.api.Assertions.assertThat;
import static org.jdbi.v3.core.locator.ClasspathSqlLocator.findSqlOnClasspath;

import java.sql.Types;

import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.statement.OutParameters;
import org.jdbi.v3.postgres.PostgresDbRule;
import org.junit.Rule;
import org.junit.Test;

public class CallTest
{
    @Rule
    public PostgresDbRule db = new PostgresDbRule();

    @Test
    public void testCall() {
        Handle handle = db.getSharedHandle();

        handle.execute(findSqlOnClasspath("create_stored_proc_add"));

        // tag::invokeProcedure[]
        OutParameters result = handle
                .createCall("{:sum = add(:a, :b)}") // <1>
                .bind("a", 13) // <2>
                .bind("b", 9) // <2>
                .registerOutParameter("sum", Types.INTEGER) // <3> <4>
                .invoke(); // <5>
        // end::invokeProcedure[]

        // tag::getOutParameters[]<commit_msg>Fix SQL call syntax<commit_after>package jdbi.doc;

import static org.assertj.core.api.Assertions.assertThat;
import static org.jdbi.v3.core.locator.ClasspathSqlLocator.findSqlOnClasspath;

import java.sql.Types;

import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.statement.OutParameters;
import org.jdbi.v3.postgres.PostgresDbRule;
import org.junit.Rule;
import org.junit.Test;

public class CallTest
{
    @Rule
    public PostgresDbRule db = new PostgresDbRule();

    @Test
    public void testCall() {
        Handle handle = db.getSharedHandle();

        handle.execute(findSqlOnClasspath("create_stored_proc_add"));

        // tag::invokeProcedure[]
        OutParameters result = handle
                .createCall("{:sum = call add(:a, :b)}") // <1>
                .bind("a", 13) // <2>
                .bind("b", 9) // <2>
                .registerOutParameter("sum", Types.INTEGER) // <3> <4>
                .invoke(); // <5>
        // end::invokeProcedure[]

        // tag::getOutParameters[]
{'fraction_non_alphanumeric': 0.1425037110341415, 'fraction_numerical': 0.012864918357248886, 'mean_word_length': 2.591474245115453, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4497678', 'n_tokens_mistral': 677, 'n_tokens_neox': 644, 'n_words': 121}