mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add glob/notglob commands to SQLTester and complete the interrupted-midway impls of the strglob() and strlike() JNI bindings.
FossilOrigin-Name: 4ba98ec0bf24c31cce498031cb3727e09f928f54ec13c76fec50e439e0f2ba15
This commit is contained in:
@ -3070,24 +3070,29 @@ JDECL(void,1set_1last_1insert_1rowid)(JENV_CSELF, jobject jpDb, jlong rowId){
|
||||
}
|
||||
|
||||
static int s3jni_strlike_glob(int isLike, JNIEnv *const env,
|
||||
jbyteArray baG, jbyteArray baT){
|
||||
jbyteArray baG, jbyteArray baT, jint escLike){
|
||||
int rc = 0;
|
||||
jbyte * const pG = JBA_TOC(baG);
|
||||
jbyte * const pT = pG ? JBA_TOC(baT) : 0;
|
||||
|
||||
OOM_CHECK(pT);
|
||||
rc = sqlite3_strglob((const char *)pG, (const char *)pT);
|
||||
|
||||
/* Note that we're relying on the byte arrays having been
|
||||
NUL-terminated on the Java side. */
|
||||
rc = isLike
|
||||
? sqlite3_strlike((const char *)pG, (const char *)pT,
|
||||
(unsigned int)escLike)
|
||||
: sqlite3_strglob((const char *)pG, (const char *)pT);
|
||||
JBA_RELEASE(baG, pG);
|
||||
JBA_RELEASE(baT, pT);
|
||||
return rc;
|
||||
}
|
||||
|
||||
JDECL(int,1strglob)(JENV_CSELF, jbyteArray baG, jbyteArray baT){
|
||||
return s3jni_strlike_glob(0, env, baG, baT);
|
||||
return s3jni_strlike_glob(0, env, baG, baT, 0);
|
||||
}
|
||||
|
||||
JDECL(int,1strlike)(JENV_CSELF, jbyteArray baG, jbyteArray baT){
|
||||
return s3jni_strlike_glob(1, env, baG, baT);
|
||||
JDECL(int,1strlike)(JENV_CSELF, jbyteArray baG, jbyteArray baT, jint escChar){
|
||||
return s3jni_strlike_glob(1, env, baG, baT, escChar);
|
||||
}
|
||||
|
||||
JDECL(jint,1shutdown)(JENV_CSELF){
|
||||
|
@ -1470,10 +1470,10 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strglob
|
||||
/*
|
||||
* Class: org_sqlite_jni_SQLite3Jni
|
||||
* Method: sqlite3_strlike
|
||||
* Signature: ([B[B)I
|
||||
* Signature: ([B[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strlike
|
||||
(JNIEnv *, jclass, jbyteArray, jbyteArray);
|
||||
(JNIEnv *, jclass, jbyteArray, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_SQLite3Jni
|
||||
|
@ -850,21 +850,28 @@ public final class SQLite3Jni {
|
||||
|
||||
public static native int sqlite3_step(@NotNull sqlite3_stmt stmt);
|
||||
|
||||
private static native int sqlite3_strglob(@NotNull byte[] glob, @NotNull byte[] txt);
|
||||
private static native int sqlite3_strglob(
|
||||
@NotNull byte[] glob, @NotNull byte[] txt
|
||||
);
|
||||
|
||||
public static int sqlite3_strglob(@NotNull String glob, @NotNull String txt){
|
||||
return sqlite3_strglob(
|
||||
glob.getBytes(StandardCharsets.UTF_8),
|
||||
txt.getBytes(StandardCharsets.UTF_8)
|
||||
(glob+"\0").getBytes(StandardCharsets.UTF_8),
|
||||
(txt+"\0").getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
}
|
||||
|
||||
private static native int sqlite3_strlike(@NotNull byte[] glob, @NotNull byte[] txt);
|
||||
private static native int sqlite3_strlike(
|
||||
@NotNull byte[] glob, @NotNull byte[] txt, int escChar
|
||||
);
|
||||
|
||||
public static int sqlite3_strlike(@NotNull String glob, @NotNull String txt){
|
||||
public static int sqlite3_strlike(
|
||||
@NotNull String glob, @NotNull String txt, char escChar
|
||||
){
|
||||
return sqlite3_strlike(
|
||||
glob.getBytes(StandardCharsets.UTF_8),
|
||||
txt.getBytes(StandardCharsets.UTF_8)
|
||||
(glob+"\0").getBytes(StandardCharsets.UTF_8),
|
||||
(txt+"\0").getBytes(StandardCharsets.UTF_8),
|
||||
(int)escChar
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -196,8 +196,8 @@ public class SQLTester {
|
||||
if( 0!=rc ){
|
||||
final String msg = sqlite3_errmsg(db);
|
||||
sqlite3_close(db);
|
||||
Util.toss(TestFailure.class, "db open failed with code",
|
||||
rc,"and message:",msg);
|
||||
Util.toss(TestFailure.class, "db open failed with code ",
|
||||
rc," and message: ",msg);
|
||||
}
|
||||
return aDb[iCurrentDb] = db;
|
||||
}
|
||||
@ -433,8 +433,20 @@ class GlobCommand extends Command {
|
||||
String[] argv, String content) throws Exception{
|
||||
argcCheck(argv,1);
|
||||
affirmNoContent(content);
|
||||
|
||||
t.incrementTestCounter();
|
||||
final String sql = t.takeInputBuffer();
|
||||
//t.verbose(argv[0]," SQL =\n",sql);
|
||||
int rc = t.execSql(null, true, true, sql);
|
||||
final String result = t.getResultBufferText().trim();
|
||||
final String sArgs = Util.argvToString(argv);
|
||||
//t.verbose(argv[0]," rc = ",rc," result buffer:\n", result,"\nargs:\n",sArgs);
|
||||
final String glob = argv[1].replace("#","[0-9]");
|
||||
t.verbose(argv[0]," is TODO. Pattern = ",glob);
|
||||
rc = sqlite3_strglob(glob, result);
|
||||
if( (negate && 0==rc) || (!negate && 0!=rc) ){
|
||||
Util.toss(TestFailure.class, this.getClass().getSimpleName(),
|
||||
" glob mismatch: ",glob," vs input: ",result);
|
||||
}
|
||||
}
|
||||
public GlobCommand(SQLTester t, String[] argv, String content) throws Exception{
|
||||
this(false, t, argv, content);
|
||||
@ -499,12 +511,7 @@ class ResultCommand extends Command {
|
||||
//t.verbose(argv[0]," SQL =\n",sql);
|
||||
int rc = t.execSql(null, true, true, sql);
|
||||
final String result = t.getResultBufferText().trim();
|
||||
StringBuilder sbExpect = new StringBuilder();
|
||||
for(int i = 1; i < argv.length; ++i ){
|
||||
if( i>1 ) sbExpect.append(" ");
|
||||
sbExpect.append( argv[i] );
|
||||
}
|
||||
final String sArgs = sbExpect.toString();
|
||||
final String sArgs = Util.argvToString(argv);
|
||||
//t.verbose(argv[0]," rc = ",rc," result buffer:\n", result,"\nargs:\n",sArgs);
|
||||
if( !result.equals(sArgs) ){
|
||||
Util.toss(TestFailure.class, argv[0]," comparison failed.");
|
||||
@ -586,8 +593,7 @@ class CommandDispatcher {
|
||||
final class Util {
|
||||
public static void toss(Class<? extends Exception> errorType, Object... msg) throws Exception {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int i = 0;
|
||||
for(Object s : msg) sb.append(((0==i++) ? "" : " ")+s);
|
||||
for(Object s : msg) sb.append(s);
|
||||
final java.lang.reflect.Constructor<? extends Exception> ctor =
|
||||
errorType.getConstructor(String.class);
|
||||
throw ctor.newInstance(sb.toString());
|
||||
@ -609,4 +615,13 @@ final class Util {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
public static String argvToString(String[] argv){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i = 1; i < argv.length; ++i ){
|
||||
if( i>1 ) sb.append(" ");
|
||||
sb.append( argv[i] );
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ select 'a', 'b';
|
||||
select 'a', 'b';
|
||||
--result a b a b
|
||||
--testcase second
|
||||
select 1
|
||||
--glob # /* ignored */
|
||||
select 123
|
||||
--glob #2#
|
||||
--testcase second
|
||||
select 'a'
|
||||
--notglob #
|
||||
|
Reference in New Issue
Block a user