github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/tests/ext_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/ncruces/go-sqlite3"
     7  	_ "github.com/ncruces/go-sqlite3/embed"
     8  	_ "github.com/ncruces/go-sqlite3/tests/testcfg"
     9  )
    10  
    11  func Test_base64(t *testing.T) {
    12  	t.Parallel()
    13  
    14  	db, err := sqlite3.Open(":memory:")
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  	defer db.Close()
    19  
    20  	// base64
    21  	stmt, _, err := db.Prepare(`SELECT base64('TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu')`)
    22  	if err != nil {
    23  		t.Error(err)
    24  	}
    25  	defer stmt.Close()
    26  
    27  	if !stmt.Step() {
    28  		t.Fatal("expected one row")
    29  	}
    30  	if got := stmt.ColumnText(0); got != "Many hands make light work." {
    31  		t.Errorf("got %q", got)
    32  	}
    33  }
    34  
    35  func Test_decimal(t *testing.T) {
    36  	t.Parallel()
    37  
    38  	db, err := sqlite3.Open(":memory:")
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  	defer db.Close()
    43  
    44  	stmt, _, err := db.Prepare(`SELECT decimal_add(decimal('0.1'), decimal('0.2')) = decimal('0.3')`)
    45  	if err != nil {
    46  		t.Error(err)
    47  	}
    48  	defer stmt.Close()
    49  
    50  	if !stmt.Step() {
    51  		t.Fatal("expected one row")
    52  	}
    53  	if !stmt.ColumnBool(0) {
    54  		t.Error("want true")
    55  	}
    56  }
    57  
    58  func Test_uint(t *testing.T) {
    59  	t.Parallel()
    60  
    61  	db, err := sqlite3.Open(":memory:")
    62  	if err != nil {
    63  		t.Fatal(err)
    64  	}
    65  	defer db.Close()
    66  
    67  	stmt, _, err := db.Prepare(`SELECT 'z2' < 'z11' COLLATE UINT`)
    68  	if err != nil {
    69  		t.Error(err)
    70  	}
    71  	defer stmt.Close()
    72  
    73  	if !stmt.Step() {
    74  		t.Fatal("expected one row")
    75  	}
    76  	if !stmt.ColumnBool(0) {
    77  		t.Error("want true")
    78  	}
    79  }