gpt4 book ai didi

sqlite - 如何从Android客户端调用zumero_internal_auth_add_user

转载 作者:行者123 更新时间:2023-12-03 15:30:51 24 4
gpt4 key购买 nike

我正在更新我的Android应用程序以使用Zumero处理数据同步。每个用户都将在服务器上获得他们自己的dbfile,以及他们自己的内部身份验证帐户。但是,我无法让zumero_internal_auth_add_user在Android中工作。

我用SQLiteDatabase.execSQL调用该函数,生成以下形式的SQL:

SELECT zumero_internal_auth_add_user(
'<ZUMERO URL>’,
'test1_users',
zumero_internal_auth_scheme('zumero_users_admin'),
'admin',
'<ADMIN_PWD>',
'username',
'pwd'
);


这将导致SQLiteException错误代码为100(未知错误)。日志显示该操作显然已成功完成(http状态代码为204:无内容),但是Zumero库无法识别此操作(也许只希望200?)并抛出异常。

06-04 23:13:42.247: V/Zumero(15442): execute for query: SELECT zumero_internal_auth_add_user(?, ?, zumero_internal_auth_scheme('zumero_users_admin'), ?, ?, ?, ?)
06-04 23:13:42.247: V/ZUMERO(15442): Network call started.
06-04 23:13:42.247: V/ZUMERO(15442): got JNI env.
06-04 23:13:42.247: V/ZUMERO(15442): Looked up java classes.
06-04 23:13:42.247: V/ZUMERO(15442): Initiating Network connection.
06-04 23:13:42.302: D/dalvikvm(15442): GC_CONCURRENT freed 132K, 2% free 9120K/9280K, paused 3ms+5ms, total 25ms
06-04 23:13:42.825: V/ZUMERO(15442): HTTP connection finished.
06-04 23:13:42.825: V/ZUMERO(15442): HTTP status code: 204.
06-04 23:13:42.825: V/ZUMERO(15442): HTTP error code: 0.
06-04 23:13:42.825: V/ZUMERO(15442): Network connection completed successfully.
06-04 23:13:42.825: W/dalvikvm(15442): threadid=13: thread exiting with uncaught exception (group=0x40b4d930)
06-04 23:13:42.833: E/AndroidRuntime(15442): FATAL EXCEPTION: AsyncTask #1
06-04 23:13:42.833: E/AndroidRuntime(15442): java.lang.RuntimeException: An error occured while executing doInBackground()
06-04 23:13:42.833: E/AndroidRuntime(15442): at android.os.AsyncTask$3.done(AsyncTask.java:299)
06-04 23:13:42.833: E/AndroidRuntime(15442): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
06-04 23:13:42.833: E/AndroidRuntime(15442): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
06-04 23:13:42.833: E/AndroidRuntime(15442): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
06-04 23:13:42.833: E/AndroidRuntime(15442): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-04 23:13:42.833: E/AndroidRuntime(15442): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-04 23:13:42.833: E/AndroidRuntime(15442): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-04 23:13:42.833: E/AndroidRuntime(15442): at java.lang.Thread.run(Thread.java:856)
06-04 23:13:42.833: E/AndroidRuntime(15442): Caused by: com.zumero.sqlite.SQLiteException: error code 100: unknown error
06-04 23:18:16.575: E/AndroidRuntime(15713): at com.zumero.sqlite.SQLiteStatement.native_execute(Native Method)
06-04 23:18:16.575: E/AndroidRuntime(15713): at com.zumero.sqlite.SQLiteStatement.execute(SQLiteStatement.java:63)
06-04 23:18:16.575: E/AndroidRuntime(15713): at com.zumero.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1810)
06-04 23:18:16.575: E/AndroidRuntime(15713): at com.example.people.ZumeroBackend.addUser(ZumeroBackend.java:31)
06-04 23:18:16.575: E/AndroidRuntime(15713): at com.example.people.PeopleProvider.insert(PeopleProvider.java:150)
06-04 23:18:16.575: E/AndroidRuntime(15713): at android.content.ContentProvider$Transport.insert(ContentProvider.java:201)
06-04 23:18:16.575: E/AndroidRuntime(15713): at android.content.ContentResolver.insert(ContentResolver.java:866)
06-04 23:18:16.575: E/AndroidRuntime(15713): at com.example.people.PeopleActivity.setAccount(PeopleActivity.java:265)
06-04 23:18:16.575: E/AndroidRuntime(15713): at com.example.people.PeopleActivity.access$3(PeopleActivity.java:262)
06-04 23:18:16.575: E/AndroidRuntime(15713): at com.example.people.PeopleActivity$4.doInBackground(PeopleActivity.java:250)
06-04 23:18:16.575: E/AndroidRuntime(15713): at com.example.people.PeopleActivity$4.doInBackground(PeopleActivity.java:1)
06-04 23:18:16.575: E/AndroidRuntime(15713): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-04 23:18:16.575: E/AndroidRuntime(15713): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-04 23:18:16.575: E/AndroidRuntime(15713): ... 4 more


如果我尝试再次添加同一用户,则操作失败并显示 zumero:unique_constraint_violation,这证实了我对原始调用成功的怀疑。我尝试在SQLite shell(在Windows上)中运行 zumero_internal_auth_add_user,并且工作正常,这表明该问题特定于Android库。我拉出zumero_log dbfile,发现在两种情况下(从Android和SQLite shell) zumero_internal_auth_add_user均返回204。

我是在做错什么,还是Zumero Android库中有错误?

最佳答案

这是我处理此用例的代码。我从未得到您看到的确切错误(错误代码100:未知错误)。我的代码针对Nexus 10上运行的zumero库的android-16版本进行了测试。

public class MainActivity extends Activity {

private File tempDBFullPath;
private String dbName;
private String cacheDir;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Get the full path to the databases directory.
File databasesPath = this.getDatabasePath("blah").getParentFile();
if (!databasesPath.isDirectory()) {
//These lines make sure that the databases directory is created.
databasesPath.mkdirs();
}
//Append the time to make sure that we create a new,empty database
//and a new internal auth db each time we run this Activity.
this.dbName = "testdb" + new Date().getTime();

this.tempDBFullPath = new File(databasesPath, dbName);
this.cacheDir = this.getCacheDir().getAbsolutePath();



//Can't do network on the main thread.
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {

@Override
protected Void doInBackground(Void... params) {
com.zumero.sqlite.SQLiteDatabase db = com.zumero.sqlite.SQLiteDatabase.openOrCreateDatabase(MainActivity.this.tempDBFullPath, null);
String userDB = MainActivity.this.dbName + "_users";
boolean bExec = false;
String serverAddress = "https://zinst12345.s.zumero.net";
String adminPassword = "PASSWORD";

Log.v("test", "======== creating internal auth ==========");

Cursor c = null;
if (bExec) {
//When I run this one, I get "com.zumero.sqlite.SQLiteException: unknown error: Queries cannot be performed using execSQL(), use query() instead."
//That behavior matches the gingerbread android database package.
db.execSQL("SELECT zumero_internal_auth_create('" + serverAddress +"', '" + userDB + "', zumero_internal_auth_scheme('zumero_users_admin'), 'admin', '" + adminPassword + "', NULL,NULL,'',zumero_named_constant('acl_who_anyone'),'',zumero_named_constant('acl_who_anyone') );)");
}
else {
//This one works.
c = db.rawQuery("SELECT zumero_internal_auth_create(?, ?, zumero_internal_auth_scheme(?), ?, ?, NULL,NULL,'',zumero_named_constant('acl_who_anyone'),'',zumero_named_constant('acl_who_anyone') );", new String[] {serverAddress, userDB, "zumero_users_admin", "admin", adminPassword });
//WATCH OUT! rawQuery doesn't actually execute until the call to moveToFirst.
c.moveToFirst();
}

Log.v("test", "======== adding user ==========");

if (bExec) {
//When I run this one, I get "com.zumero.sqlite.SQLiteException: unknown error: Queries cannot be performed using execSQL(), use query() instead."
db.execSQL("SELECT zumero_internal_auth_add_user('" + serverAddress + "', '" + userDB + "', zumero_internal_auth_scheme('zumero_users_admin'), 'admin', '" + adminPassword + "', 'newUsername', 'newPassword');");
}
else {
//This one works.
c = db.rawQuery("SELECT zumero_internal_auth_add_user(?, ?, zumero_internal_auth_scheme(?), ?, ?, ?, ?);", new String[] {serverAddress, userDB, "zumero_users_admin", "admin", adminPassword, "newUsername", "newPassword" } );
c.moveToFirst();
}

Log.v("test", "======== creating zumero acl table for this DB file. ==========");

c = db.rawQuery("SELECT zumero_define_acl_table('main');", null);
c.moveToFirst();

Log.v("test", "======== giving newUsername full permission to this DB file. ==========");

db.execSQL("INSERT INTO z_acl (scheme,who,tbl,op,result) VALUES (zumero_internal_auth_scheme('" + userDB + "'), zumero_named_constant('acl_who_specific_user') || 'newUsername', '', '*', zumero_named_constant('acl_result_allow'));");

Log.v("test", "======== executing admin sync so that the server has the new acl table ==========");

c = db.rawQuery("SELECT zumero_sync('main', ?, ?, zumero_internal_auth_scheme(?), ?, ?, ?);", new String[] {serverAddress, dbName, "zumero_users_admin", "admin", adminPassword, MainActivity.this.cacheDir } );
c.moveToFirst();

Log.v("test", "======== executing sync as the new user. ==========");

c = db.rawQuery("SELECT zumero_sync('main', ?, ?, zumero_internal_auth_scheme(?), ?, ?, ?);", new String[] {serverAddress, dbName, userDB, "newUsername", "newPassword", MainActivity.this.cacheDir } );
c.moveToFirst();

db.close();

return null;
}
};

task.execute((Void)null);

setContentView(R.layout.activity_main);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);

return true;
}

}

关于sqlite - 如何从Android客户端调用zumero_internal_auth_add_user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16943396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com