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

@ -81,6 +81,7 @@ JAVA_FILES.main := $(patsubst %,$(dir.src.jni)/%,\
ScalarFunction.java \
SQLFunction.java \
SQLite3Jni.java \
TableColumnMetadata.java \
Tester1.java \
TraceV2Callback.java \
UpdateHookCallback.java \

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);
}

View File

@ -1,5 +1,5 @@
C Export\ssqlite3_(db_)free_memory()\sand\ssqlite3_table_column_metadata()\sto\sJNI.\sFurther\sinternals\srenaming\sfor\sconsistency\sand\slegibility.
D 2023-08-31T14:57:01.532
C Add\sconvenience\soverloads\sof\sJNI\ssqlite3_table_column_metadata()\sto\ssimplify\susage.
D 2023-08-31T15:24:46.471
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -234,7 +234,7 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c
F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9
F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
F ext/jni/GNUmakefile 374873bf6d2cd6ceafb458e28b59140dbb074f01f7adddf7e15a3ee3daf44551
F ext/jni/GNUmakefile b6ae6d04cc33f2300ab7177bd5db1ecfbc8627f76fee6aec441f980e57594291
F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9
F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa
F ext/jni/src/c/sqlite3-jni.c 2364ccb4445c5f45a4d4b80d28455fe0c547f5529e5bd8610b4ba3811c82cc78
@ -262,9 +262,10 @@ F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7c
F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java 16042be9d072a26dbb2f1b1b63e7639989b747bb80d2bd667ba4f7555f56a825
F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c
F ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java c2748ab52856075b053a55b317988d95dc7fb4d3d42520f8c33573effe1cd185
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 548ab462e161118b50a614a8bbc2fc2abd507f9b0632267fc78bdd8926ad0807
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 5ac577b1f2290b3ef6e974e5d1530c380c09708ffedb42797dcfc2b8d016904d
F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c
F ext/jni/src/org/sqlite/jni/Tester1.java 05750f0ea53057de146fce8d06b7314009732de06f1e4843c87aa28ba940d6f7
F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab
F ext/jni/src/org/sqlite/jni/Tester1.java 96fefa219302e3e82f720baf082533fed98e6d31fe8887db5e14c150f1d2b3c1
F ext/jni/src/org/sqlite/jni/TesterFts5.java 6f135c60e24c89e8eecb9fe61dde0f3bb2906de668ca6c9186bcf34bdaf94629
F ext/jni/src/org/sqlite/jni/TraceV2Callback.java 641926b05a772c2c05c842a81aa839053ba4a13b78ef04b402f5705d060c6246
F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java be2bc96ff4f56b3c1fd18ae7dba9b207b25b6c123b8a5fd2f7aaf3cc208d8b7d
@ -2115,11 +2116,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 443ea20ddb0f3bf5d77ef59cd4678f0e32d7da328002bb44d6fc080a53a37e29
R d454ebcc01c88272e67e43cac0f5ee2a
T *branch * jni-client-data
T *sym-jni-client-data *
T -sym-db-client-data * Cancelled\sby\sbranch.
P 7c86aa3400ed591d38c1828f366f4b5de97954c2b301919d3f06d9c2d3d7d1f2
R b592252ce8c67a9da162168a99edb15f
U stephan
Z c9e44a2d4b476765181f0fdc6d845bb0
Z b8513dbd5fd3543a1785ad43823c91b6
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
7c86aa3400ed591d38c1828f366f4b5de97954c2b301919d3f06d9c2d3d7d1f2
faf4e6d398f444d970be8b1364c984c67ccbc5f8a27f3aa93f05b8a8de7bec9b