// Code generated by modernc.org/undup from the per-target sqlite_*.go files; DO NOT EDIT.

//go:build (linux && 386) || (linux && amd64) || (linux && arm) || (linux && arm64) || (linux && ppc64le) || (linux && riscv64)

package sqlite3

import (
	"unsafe"

	"modernc.org/libc"
)

// C documentation
//
//	/*
//	** Open a new database handle.
//	*/
func Xsqlite3_open16(tls *libc.TLS, zFilename uintptr, ppDb uintptr) (r int32) {
	var pVal, zFilename8 uintptr
	var rc int32
	var v1 Tu8
	_, _, _, _ = pVal, rc, zFilename8, v1
	**(**uintptr)(__ccgo_up(ppDb)) = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	if zFilename == uintptr(0) {
		zFilename = __ccgo_ts + 26268
	}
	pVal = _sqlite3ValueNew(tls, uintptr(0))
	_sqlite3ValueSetStr(tls, pVal, -int32(1), zFilename, uint8(SQLITE_UTF16LE), libc.UintptrFromInt32(0))
	zFilename8 = _sqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
	if zFilename8 != 0 {
		rc = _openDatabase(tls, zFilename8, ppDb, libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)), uintptr(0))
		if rc == SQLITE_OK && !(libc.Int32FromUint16((*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).FaDb))).FpSchema)).FschemaFlags)&libc.Int32FromInt32(DB_SchemaLoaded) == libc.Int32FromInt32(DB_SchemaLoaded)) {
			v1 = libc.Uint8FromInt32(SQLITE_UTF16LE)
			(*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).Fenc = v1
			(*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).FaDb))).FpSchema)).Fenc = v1
		}
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	_sqlite3ValueFree(tls, pVal)
	return rc & int32(0xff)
}
