1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add convenience overloads of JNI sqlite3_table_column_metadata() to simplify usage.

FossilOrigin-Name: faf4e6d398f444d970be8b1364c984c67ccbc5f8a27f3aa93f05b8a8de7bec9b
This commit is contained in:
stephan
2023-08-31 15:24:46 +00:00
parent 0c2ba994d2
commit 062bafb851
6 changed files with 86 additions and 12 deletions

View File

@ -1373,6 +1373,34 @@ public final class SQLite3Jni {
@Nullable OutputPointer.Bool pAutoinc
);
/**
Convenience overload which returns its results via a single
output object. If this function returns non-0 (error), the the
contents of the output object are not modified.
*/
public static int sqlite3_table_column_metadata(
@NotNull sqlite3 db, @NotNull String zDbName,
@NotNull String zTableName, @NotNull String zColumnName,
@NotNull TableColumnMetadata out){
return sqlite3_table_column_metadata(
db, zDbName, zTableName, zColumnName,
out.pzDataType, out.pzCollSeq, out.pNotNull,
out.pPrimaryKey, out.pAutoinc);
}
/**
Convenience overload which returns the column metadata object on
success and null on error.
*/
public static TableColumnMetadata sqlite3_table_column_metadata(
@NotNull sqlite3 db, @NotNull String zDbName,
@NotNull String zTableName, @NotNull String zColumnName){
final TableColumnMetadata out = new TableColumnMetadata();
return 0==sqlite3_table_column_metadata(
db, zDbName, zTableName, zColumnName, out
) ? out : null;
}
@Canonical
public static native int sqlite3_threadsafe();

View File

@ -0,0 +1,35 @@
/*
** 2023-07-21
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file is part of the JNI bindings for the sqlite3 C API.
*/
package org.sqlite.jni;
/**
A wrapper object for use with sqlite3_table_column_metadata().
They are populated only via that interface.
*/
public final class TableColumnMetadata {
OutputPointer.Bool pNotNull = new OutputPointer.Bool();
OutputPointer.Bool pPrimaryKey = new OutputPointer.Bool();
OutputPointer.Bool pAutoinc = new OutputPointer.Bool();
OutputPointer.String pzCollSeq = new OutputPointer.String();
OutputPointer.String pzDataType = new OutputPointer.String();
public TableColumnMetadata(){
}
public String getDataType(){ return pzDataType.value; }
public String getCollation(){ return pzCollSeq.value; }
public boolean isNotNull(){ return pNotNull.value; }
public boolean isPrimaryKey(){ return pPrimaryKey.value; }
public boolean isAutoincrement(){ return pAutoinc.value; }
}

View File

@ -1381,6 +1381,18 @@ public class Tester1 implements Runnable {
affirm( bNotNull.value );
affirm( "noCase".equals(zCollSeq.value) );
affirm( "duck".equals(zDataType.value) );
final TableColumnMetadata m =
sqlite3_table_column_metadata(db, "main", "t", "a");
affirm( null != m );
affirm( bPrimaryKey.value == m.isPrimaryKey() );
affirm( bAutoinc.value == m.isAutoincrement() );
affirm( bNotNull.value == m.isNotNull() );
affirm( zCollSeq.value.equals(m.getCollation()) );
affirm( zDataType.value.equals(m.getDataType()) );
affirm( null == sqlite3_table_column_metadata(db, "nope", "t", "a") );
sqlite3_close_v2(db);
}