• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Sending multiple rows from SQLite in Android to MySQL

What is wrong in the code below?

The idea is to make a query to the local database (SQLite) from Android and therefore get the data resulting from this query and sends them through the JSON into a central database in MySQL.

The solution I have here should apparently work (i.e. send all rows from the local database in SQLite).

But actually this is not what happens: it is only sent to the first line. Someone can help me on this? I appreciate the help.

@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int sucesso;
Log.d("CARREGAMENTO LINHAS: ", "Inicializar");

ControllerPontos datasource = new ControllerPontos(getApplicationContext());
List<Pontos> pontosJogador = datasource.getRowsNotUploaded();
Log.d("CARREGAMENTO LINHAS: ", "OK");

if (pontosJogador.size() > 0) {
for (Pontos linha : pontosJogador) {
String log = "IDInscricao: "+linha.getIDInscricao()+" ,IDMissao: " + linha.getIDMissao() + " ,IDNivel: " + linha.getIDNivel() +
"IDTarefa: "+ linha.getIDTarefa()+"data: "+linha.getData()+"tempo: "+linha.getTempo()+"pontos: "+linha.getPontos();
Log.d("LISTAGEM: ", log);

idInscricao = linha.getIDInscricao();
idMissao = linha.getIDMissao();
idNivel = linha.getIDNivel();
idTarefa = linha.getIDTarefa();
data = linha.getData();
tempo = linha.getTempo();
pontos = linha.getPontos();

// parametros da lista
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("idInscricao", Integer.toBinaryString(idInscricao)));
params.add(new BasicNameValuePair("idMissao", Integer.toBinaryString(idMissao)));
params.add(new BasicNameValuePair("idNivel", Integer.toBinaryString(idNivel)));
params.add(new BasicNameValuePair("idTarefa", Integer.toBinaryString(idTarefa)));
params.add(new BasicNameValuePair("data", data));
params.add(new BasicNameValuePair("tempo", Integer.toBinaryString(tempo)));
params.add(new BasicNameValuePair("pontos", Integer.toBinaryString(pontos)));

// vamos fazer o sincronismo linha a linha da tabela
try {
Log.d("ENVIO PONTOS", "Inicializar");

//Posting user data to script
JSONObject json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);

// full json response
Log.d("Tentar sincronizacao...", json.toString());

// verificacao do sucesso
sucesso = json.getInt(TAG_SUCESSO);
if (sucesso == 1) {
Log.d("Pontos adicionados!", json.toString());
finish();
return json.getString(TAG_MENSAGEM);
}else{
Log.d("Envio de pontos falhou!", json.getString(TAG_MENSAGEM));
return json.getString(TAG_MENSAGEM);

}
} catch (JSONException e) {
e.printStackTrace();
}

}// fecha FOR
}
else{
Log.d("CARREGAMENTO LINHAS: ", "NAO HA LINHAS");
}
return null;
} // fecha doInBack

/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();

if (file_url != null){
Toast.makeText(UploadDados.this, file_url, Toast.LENGTH_LONG).show();
}
}

} //fecha sincronismo
 
Back
Top Bottom