/ / Kā zvanīt zumero_internal_auth_add_user no Android klienta - sqlite, zumero

Kā zvanīt zumero_internal_auth_add_user no Android klienta - sqlite, zumero

Es atjauninu savu Android lietotni, lai izmantotu Zumero, lai apstrādātu datu sinhronizāciju. Katrs lietotājs saņems savu dbfile serverī, kā arī savu iekšējo autoru kontu. Tomēr es nevaru saņemt zumero_internal_auth_add_user strādāt Android ierīcē.

Es izmantoju funkciju ar SQLiteDatabase.execSQL, veidojot SQL formu:

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

Tas izraisa SQLiteException ar kļūdas kodu 100(nezināma kļūda). Raksti rāda, ka operācija acīmredzot ir izdevies (http statusa kods ir 204: nav satura), bet Zumero bibliotēka to neatzina (varbūt tā tikai gaida 200?) Un izmežo izņēmumu.

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

Ja mēģinu vēlreiz pievienot to pašu lietotāju, operācija neizdodas zumero:unique_constraint_violation, apstiprinot manas aizdomas, ka sākotnējais zvans ir sekmīgs. Es mēģināju darboties zumero_internal_auth_add_user SQLite apvalkā (operētājsistēmā Windows), un tā strādāja labi, norādot, ka problēma ir raksturīga Android lib. Es velk zumero_log dbfile un to atradu zumero_internal_auth_add_user abos gadījumos atgriež 204 (no Android un SQLite apvalks).

Vai es kaut ko daru nepareizi, vai ir bugs Zumero Android bibliotēkā?

Atbildes:

1 atbilde Nr. 1

Šeit ir mans kods, kas apstrādā šo lietojuma gadījumu. Es nekad neesmu saņēmis precīzu kļūdu, kuru redzējāt (kļūdas kods 100: nezināma kļūda). Mans kods tika pārbaudīts saskaņā ar zumero libs android-16 versiju, kas darbojas ar Nexus 10.

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

}

Saistītie jautājumi


Komentāri (0)

Pievieno komentāru