I'm facing an issue in my application where I send the server request once and receive a single response but my request has created duplicate rows in the database. The only primary key in the database table is the row id which gets incremented every time a request is sent so duplicate rows of values get created with different row ids. I'm using Xamarin Android. Could you please let me know if this issue is a bug related to Xamarin and if they is any way in which this can be fixed?
Thank you.
Edit:
This is my code:
I call this method in my OnCreate()
public void SendMobileNo(Activity activity)
{
Services_GetValue.GetValue client = new Services_GetValue.GetValue();
Services_GetValue.GetValueRequest request = new Services_GetValue.GetValueRequest()
{
key = "abac",
PhoneNo = "1234567890"
};
client.BeginCheckPhone(request, (ar) => {
Services_GetValue.GetValueResponse response = client.EndCheckPhone(ar);
this.IsPhoneValid = response.IsValidPhoneNo;
activity.RunOnUiThread (() => {
if (SendMobileNoCompleted != null)
{
this.SendMobileNoCompleted();
this.SendMobileNoCompleted = null;
}
});
}, null);
client.CheckPhone(request);
}
I have created a Proxy in WebReferences package with the name "Services_GetValue.GetValue" and it is a SOAP webservice.
Related
This is my android code :
ParseObject parseObject = new ParseObject("likes");
ParseObject parseuser=ParseObject.createWithoutData(ParseUser.class,post.getPosAuthorObjectId());
ParseObject parsepost=ParseObject.createWithoutData("posts",post.getObjectId());
parsepost.put("postAuthor",parseuser);
parseObject.put("ownerId", ParseObject.createWithoutData(ParseUser.class, ParseUser.getCurrentUser().getObjectId()));
parseObject.put("postId",parsepost);
parseObject.saveInBackground
I am trying to send some data regarding the user's id along with the post object so as to save the post object int the "likes" class and do changes in the post owner's attributes using masterkey without fetching the id of the post owner in a separate query as it is already stored in my android code .In my experimental beforeSave():
Parse.Cloud.beforeSave("likes",function(request,response){
var posts = Parse.Object.extend("posts");
var post=new posts();
var post=request.object.get("postId");
var user=Parse.Object.extend(Parse.User);
var user=new Parse.User();
var id =post.object.get("postAuthor").id;
if(id!=null){
response.success();
}
else{
response.error("The id is null");
}
});
Basically I am trying to retrieve the user id saved in the postobject and sent to the request parameter .But the output of my experiment is always null.
You're extending the Parse.Object for the user class and setting a new user using the same variable name. You can just get rid of the first var user line completely, since new Parse.User() works by default without any extending.
Anyway, try just console.log( request.object ); to see what you're actually passing in.
I'm using Azure Mobile Services with an android application which I am trying to get working with a SQL database in Azure. Im using a server-side JavaScript function within Mobile Services to handle the insertion and update of data. Insertion of new data operates correctly, however I cannot update any rows with the function.
The error I received is: 409 - error: Could not insert the item because an item with that id already exists.
It seems as though it is trying to insert instead of update, but I can't figure out the solution. Help is much appreciated!
Here's my server-side script from Azure:
function insert(item, user, request) {
var table = tables.getTable('Reviews');
table.where({
text: item.id
}).read({
success: upsertItem
});
function upsertItem(existingItems) {
if (existingItems.length == 0) {
item.numReviews = 1;
item.rating = item.reviews;
request.execute();
} else {
item.id = existingItems[0].id;
item.numReviews = existingItems[0].numReviews + 1;
var average = existingItems[0].reviews / item.numReviews;
item.reviews = existingItems[0].reviews + item.reviews;
item.rating = average;
table.update(item, {
success: function(updatedItem) {
request.respond(200, updatedItem)
}
});
}
}
}
For your initial query, you want to query by the id field:
table.where({
id: item.id
}).read({
success: upsertItem
});
I am going to save records to Parse database.
Saving to Parse:
ParseObject database = null;
database = new ParseObject("Record_db");
database.put("period_ref", current1_draw_ref_I);
database.put("remark", "na");
database.put("publishing", "publishing");
database.saveInBackground();
Cloud Code:
Parse.Cloud.beforeSave("check_duplicate", function(request, response)
{
var DB = Parse.Object.extend("Record_db");
var query = new Parse.Query(DB);
query.equalTo("period_ref", request.object.get("period_ref"));
query.first
({
success: function(object)
{
if (object)
{
response.error("A Period with this ref already exists.");
}
else
{
response.success();
}
},
error: function(error)
{
response.error("Could not validate uniqueness for this period ref object.");
}
});
});
Question:
The records can be saved to the Record_db database. But I do not know how to connect and invoke the "check_duplicate" cloud function for checking duplicate beforeSave. I found there are no tutorials or documentations on such basic operations.
How such beforesave works and when should it be called???
Could you please kindly tell me how to write in the Android code to check duplicate (if duplicate then do not save, if it is new record, then save to Parse DB) and then save to Parse? This basics stuck me for a week which is so desperating...Many thanks for your help in advance.
You are very close with your implementation, however, the before*/after* methods require the parameter being the actual classname the code should be run for, not a random method name.
beforeSave,afterSave and beforeDelete,afterDelete, get invoked automatically by Parse once an object of the class defined in the function definition is saved.
So instead of naming the method check_duplicate, use the classname Record_db like so:
Parse.Cloud.beforeSave("Record_db", function(request, response) {
//... your code ...
});
Also please note that these methods run on every save, not just on object creation, you can use request.object.isNew() to check if the object that gets saved is new or already existed.
I have download yaxim source code from github yaxim link Now I want to get the member of
conference , I tried below code but its not working,
String room = "test#conference.abc";
Connection xmppConnection;
ConnectionThread connectionThread = AccountManager.getInstance()
.getAccount(account).getConnectionThread();
if (connectionThread == null) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
return true;
}
xmppConnection = connectionThread.getXMPPConnection();
MultiUserChat userChat = new MultiUserChat(xmppConnection, room);
Iterator<String> roomUsers = userChat.getOccupants();
System.out.println("roomUsers count === "+userChat.getOccupantsCount());
while (roomUsers.hasNext()) {
String roomOccupants = (String) roomUsers.next();
System.out.println("room users ==== "+roomOccupants);
}
but roomUsers count returns 0.
if any one know other way for getting users list from conference room , then let me know
You need to join the MUC in order to see its members.
in my app i have two edit boxes for email and username. Whatever the user types in it i am trying to move it over an url as follows
http//xxxxxxx.com/id?mail=*email&user=*usernane
By this i am getting a return data from the url, this is what i am doing if network is available. But if network is not available i am storing those two values in Sqlite database and in another activity if network is available i will be fetching the above said data and i will move them to the server.
My problem is, at the time of network not available if the user tries to send two set of username and email to the server it gets stored in database. How can i store those values in an array and how can i fetch them one by one. Please help me friends
Following is the part of my code for database
off = openOrCreateDatabase("Offline.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
off.setVersion(1);
off.setLocale(Locale.getDefault());
off.setLockingEnabled(true);
final String CREATE_TABLE_OFFLINEDATA ="CREATE TABLE IF NOT EXISTS offlinedata(spotid INTEGER, username TEXT, email TEXT);";
off.execSQL(CREATE_TABLE_OFFLINEDATA);
ContentValues values = new ContentValues();
values.put("id", millis);
values.put("name", username);
values.put("mail", email);
off.insert("offlinedata", null, values);
Cursor con = off.rawQuery("select * from offlinedata" , null);
if (con != null )
{
if (con.moveToFirst())
{
do
{
int spotid = con.getInt(con.getColumnIndex("id"));
String first = con.getString(con.getColumnIndex("username"));
String middle = con.getString(con.getColumnIndex("email"));
}
while (con.moveToNext());
}
}
off.close();
Please help me friends....
From looking at your sample code, it seems like you're storing them properly(ish), and you've managed an exhaustive job fetching them in a really narrow scope, so make first and middle more globalish and since you have two strings available, put them in an array.
Though I must say if this is your actual code it probably won't work the way you want this whole offline thing to work.