Android Question About duplicate entry in a database

igscomp

Member
Licensed User
Longtime User
Hi, i don't know how to detect a duplicate entry on my database.

I obtain a Job.Success = false but a don't know how can i know that is not success for this reason :(

Can you help me?
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
       'Log("Main.Jobdone("&Job.JobName&"), true")
       'Log("JobName: "&Job.JobName&" / Response from server: " & Job.GetString)

    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
     log($"Error: ${Job.ErrorMessage} "$)
    End If
    Job.Release
 
Upvote 0

igscomp

Member
Licensed User
Longtime User
B4X:
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
       'Log("Main.Jobdone("&Job.JobName&"), true")
       'Log("JobName: "&Job.JobName&" / Response from server: " & Job.GetString)

    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
     log($"Error: ${Job.ErrorMessage} "$)
    End If
    Job.Release

With this i obtain "Error: Internal Server Error" but i don't know if the error is for duplicate or not, any idea?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Can anyone help me please?
It's really tough to help, since in the end we really only have the information that you are getting a internal server error. We have no code that shows what you are trying to GET/POST/WhoKnowsWhatElse to a server, nor do we have any idea of what the server expects (server API) or what the code is on the server side that may crap out. We don't even know if you are dealing with a issue of duplicate records, since we don't even know if any updates work (you've not told us/shown us any working code/sample data vs non-working code/sample data).
 
Upvote 0

igscomp

Member
Licensed User
Longtime User
I think code is not neccesary. I only try to insert a record. If this record is duplicate, server sais to me "Internal Server Error". The question is how can i know that this server error is for duplicate entry and not for other reason. Do you know how to do it?

B4A log shows to me this issue, so i think that there is any way to detect it. See attached imagen.
 

Attachments

  • Screenshot_1.jpg
    Screenshot_1.jpg
    31.1 KB · Views: 200
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The question is how can i know that this server error is for duplicate entry and not for other reason. Do you know how to do it?
If the server just throws a generic 500 code without explaining exactly why, then you're out of luck. Unless you have access to the source and then you could modify the response of the server
B4A log shows to me this issue, so i think that there is any way to detect it
How are you getting these error messages/warnings? Where do they come from? Are these messages from the server?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
How are you getting these error messages/warnings? Where do they come from? Are these messages from the server?
i hope i´m not wrong
I obtain a Job.Success = false but a don't know how can i know that is not success for this reason :(
My answer was
B4X:
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
       'Log("Main.Jobdone("&Job.JobName&"), true")
       'Log("JobName: "&Job.JobName&" / Response from server: " & Job.GetString)

    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
     log($"Error: ${Job.ErrorMessage} "$)
    End If
    Job.Release

so i expect the error he got is coming from the webapi he is calling (but i don´t know).

With this i obtain "Error: Internal Server Error"
Based on this it is such a result. I recognized the "Error: " in the result


But what he is calling, what the server code is. No idea. He is successfully hiding the relevant infos.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I think code is not neccesary. I only try to insert a record. If this record is duplicate, server sais to me "Internal Server Error". The question is how can i know that this server error is for duplicate entry and not for other reason. Do you know how to do it?

B4A log shows to me this issue, so i think that there is any way to detect it. See attached imagen.

Based on what I can see in this screen shot this is a SQL problem rather than a B4A problem. Now assuming you are using MYSQL...

Check the definition of the table, FuncionDiaria, have you defined any of the columns as being UNIQUE or PRIMARY?

if so, does they need to be?

You could also use the ON DUPLICATE KEY UPDATE statement to update the row in the database if the INSERT fails.
https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
 
Upvote 0

igscomp

Member
Licensed User
Longtime User
If the server just throws a generic 500 code without explaining exactly why, then you're out of luck. Unless you have access to the source and then you could modify the response of the server

How are you getting these error messages/warnings? Where do they come from? Are these messages from the server?

I obtain this messages on the right of B4A IDE, i think that is a log, i can see "LogCat connected to: B4A-Bridge: Acer B1-730HD". I read that this a is the phone Log. LogCat is an object but i don't know hoy to read this message inside the app, any idea?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Start with helping us helping you.

Post ALL relevant code which insert new items in the Database, post the full error if you ran into errors.
Based on the error i guess you are setting an value from the database which is an integer but which does not allowed to have multiple datasets with the same id. Are you trying to set the value by yourself?

Really hard to help here
 
Upvote 0

igscomp

Member
Licensed User
Longtime User
I solve my problem with the "ON DUPLICATE KEY UPDATE statement".

I only need to know how to detect a duplicate record! Definition database es correct, i need this keys!

I think code is irrelevant. Database table definition is irrelevant. If a try to insert twice the same information, how can i know this situation by code??? Why B4A IDE can detect it?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Why B4A IDE can detect it?
That's just it. Without code we don't know why you are getting these log entries in B4A. If you were doing local SQL inserts, that may explain it, but since you are doing a HTTP request to update data, it does not seem to make sense.
 
Upvote 0
Top