i'm developping an android application that need to browse a MySQL Database.
I've suceeded on getting a infortion when i want all information on a table, the probleme is, when i want to add parameter like SELECT * FROM TABLE WHERE Name=name i dont know how to add he parameter on the HTTP link.
This is the link to get all Countries " http://cookndinner.atwebpages.com/api/countries " this one works well ( you can try it ) but when i want to select a country going by Code = Fr with this sql request SELECT * FROM COUNTRIES WHERE CODE=FR it doesnt work.
I tried this link : http://cookndinner.atwebpages.com/api/countries/
this one : http://cookndinner.atwebpages.com/api/countries/FR
and this one : http://cookndinner.atwebpages.com/api/countries/code=FR
none of it are working, and it just give all information on the table and doesn't add the parameter
I also trid this one for another table : http://cookndinner.atwebpages.com/api/users?email=louisard2#gmail.com&password=bankai123
but it's not working either
COuld someone help me and indicate how to insert SQL Parameter on Http links pls or if you know a tutorial that may be useful
Thank you
PS : the php part is already done
Starting from the beginning, make sure your query in PHP looks like this:
$code = $_GET['code'];
$result = mysqli_query($con,"SELECT * FROM countries WHERE code = '$code'");
Then your URI should look like this:
String url_get_country = "http://yourHostName/nameOfPhPFile.php?code=" + code
You can pass code as a parameter in method. If this doesn't work, you can change the SQL query to ...
... where code like '$code'
Related
I have been trying to retrieve information from querying a specific Asset(Story/Defect) on V1 using the VersionOne.SDK.Java.APIClient. I have been able to retrieve information like ID.Number, Status.Name but not Requests.Custom_SFDCChangeReqID2 under a Story or a Defect.
I check the metadata for:
https://.../Story?xsl=api.xsl
https://.../meta.V1/Defect?xsl=api.xsl
https://.../meta.V1/Request?xsl=api.xsl
And the naming and information looks right.
Here is my code:
IAssetType type = metaModel.getAssetType("Story");
IAttributeDefinition requestCRIDAttribute = type.getAttributeDefinition("Requests.Custom_SFDCChangeReqID2");
IAttributeDefinition idNumberAttribute = type.getAttributeDefinition("ID.Number")
Query query = new Query(type);
query.getSelection().add(requestCRIDAttribute);
query.getSelection().add(idNumberAttribute);
Asset[] results = v1Api.retrieve(query).getAssets();
String RequestCRID= result.getAttribute(requestCRIDAttribute).getValue().toString();
String IdNumber= result.getAttribute(idNumberAttribute).getValue().toString();
At this point, I can get some values for ID.Number but I am not able to retrieving any information for the value Custom_SFDCChangeReqID2.
When I run the restful query to retrieve information using a browser from a server standpoint it works and it does retrieve the information I am looking for. I used this syntax:
https://.../rest-1.v1/Data/Story?sel=Number,ID,Story.Requests.Custom_SFDCChangeReqID2,Story.
Alex: Remember that Results is an array of Asset´s, so I guess you should be accessing the information using something like
String RequestCRID= results[0].getAttribute(requestCRIDAttribute).getValue().toString();
String IdNumber= results[0].getAttribute(idNumberAttribute).getValue().toString();
or Iterate through the array.
Also notice that you have defined:
Asset[] results and not result
Hi thanks for your answer! I completely forgot about representing the loop, I was too focus on the retriving information part, yes I was actually using a loop and yes I created a temporary variable to check what I was getting from the query in the form
Because I was getting the variables one by one so I was only using the first record. My code works after all. It was just that What I was querying didn't contain any information of my use, that's why I was not finding any. Anyway thanks for your comment and observations
Recently, one of our clients reported not being able to create a table based on a query against a view. That said, they were able to save the result of a query against a table into another table. This issue spawned a more implementation focused question using the Java client libraries. Specifically, is there any way to save the result set of a query against a view to a table using the Java client library? I will be digging and post anything that I find. That said, any early guidance would be appreciated!
To be specific and add more context, I note that the the following process failed when the query was run against a union view.
java -jar BigQueryToCloudExporter.jar ./GAFastAccessKey.p12 '' "
Select date(date_add('2014-08-09',floor(datediff(date(sec_to_timestamp(visitstarttime)),'2014-08-03')/7)*7,"DAY")) WeekEndDate
, hits.eventinfo.eventaction GA_RentalNo
, count(distinct visitID) PDP_PPC
FROM (TABLE_DATE_RANGE([Union_View.GA],
TIMESTAMP('2014-08-30'),
TIMESTAMP('2014-09-13')))
where hits.eventinfo.eventcategory='property attributes'
and brandId=121
--hits.eventinfo.eventcategory='property inquiry'
and trafficsource.medium like '%cpc%'
--and trafficsource.campaign not like '%ppb%'
and trafficsource.campaign like '%mpm%'
group each by WeekEndDate, GA_XXXXXX
order by WeekEndDate, GA_XXXXXX limit 100" StagingQueryTable QueryTable AVRO gs://XXXXXX/QueryTable*.avro
On the other hand, the following process succeeded when the query was made against a BigQuery table (keeping everything else same).
java -jar BigQueryToCloudExporter.jar ./GAFastAccessKey.p12 '' "
Select date(date_add('2014-08-09',floor(datediff(date(sec_to_timestamp(visitstarttime)),'2014-08-03')/7)*7,"DAY")) WeekEndDate
, hits.eventinfo.eventaction GA_XXXXXX
, count(distinct visitID) PDP_PPC
FROM (TABLE_DATE_RANGE([XXXXXX.ga_sessions_],
TIMESTAMP('2014-08-30'),
TIMESTAMP('2014-09-13')))
where hits.eventinfo.eventcategory='property attributes'
and brandId=121
--hits.eventinfo.eventcategory='property inquiry'
and trafficsource.medium like '%cpc%'
--and trafficsource.campaign not like '%ppb%'
and trafficsource.campaign like '%mpm%'
group each by WeekEndDate, GA_RentalNo
order by WeekEndDate, GA_XXXXXX limit 100" StagingQueryTable QueryTable AVRO gs://XXXXXX/QueryTable*.avro
My Logcat shows me (correctly) all messages that I want returned, but when I ask the code to display the same thing on another php page, it goes completely wack.
Note that is this code, $from = "r", and $to = "".
Here is my code:
<?php
session_start();
/* connect to database */
$db = mysql_connect("localhost", "root", "root");
if (!$db)
die('could not connect');
mysql_select_db('androidp2p')
or die("could not select database");
/* variables */
$from = mysql_real_escape_string($_POST['from']);
$to = mysql_real_escape_string($_POST['to']);
$message = mysql_real_escape_string($_POST['message']);
/* conditional code */
if (isset ($POST['to']))
{
/* user wants to send a message */
$query = "INSERT INTO messages (fromuser, touser, message) VALUES ('$from', '$to', '$message')";
mysql_query($query)
or die("\n\ndatabase error!\n". mysql_error());
echo "ok. Messages have been saved.";
}
else //if (!isset ($POST['to']))
{
/* user wants to retrieve his messages */
$query = "SELECT * FROM messages WHERE touser='$from'";
/* echo test 1 */
echo $query;
$result = mysql_query($query)
or die("\n\ndatabase error!\n". mysql_error());
$mailbox = array();
while($row = mysql_fetch_assoc($result))
{
$mailbox[] = $row;
}
/* echo test 2 */
echo "{ \"mailbox\":".json_encode($mailbox)." }";
$name = "{ \"mailbox\":".json_encode($mailbox)." }";
$_SESSION['myValue']=$name;
}
?>
On page 2 (test.php):
<?php
session_start();
echo $_SESSION['myValue'];
?>
Here are the entries in the db:
This is my logCat:
I/RESPONSE(4591): SELECT * FROM messages WHERE touser='r'
I/RESPONSE(4591): { "mailbox":[{"id":"117","fromuser":"qw","touser":"r","message":"zx","timestamp":"2013-04-13 01:30:59"}] }
Now above I want you to see that touser is r. This entry (in the db) is what I wanted to return, i.e. all entries where the field "touser" contains the value "r".
Now, this is my test.php page:
{ "mailbox":[{"id":"132","fromuser":"r","touser":"","message":"","timestamp":"2013-04-13 15:45:03"},{"id":"123","fromuser":"r","touser":"","message":"","timestamp":"2013-04-13 13:41:23"},{"id":"122","fromuser":"r","touser":"","message":"","timestamp":"2013-04-13 13:30:53"},{"id":"133","fromuser":"","touser":"","message":"","timestamp":"2013-04-13 15:45:21"}] }
EDITED:
As you would see, it returned all touser entries that were blank (or null). My interpretation of this behaviour is that while the code is running, the $from variable is in fact 'r' (and that's why it's saved in logcat correctly), but after the code executes there is presently no value in $from so it just outputs the result for $from = null.
Should php be doing this? I thought that whatever code was executed and echoed at the time would have been output on the page and STAYED there until I re-ran the code. Any suggestions on how to fix this?
EDITED
The point of all this is to use the JSONParser code I got from here, to get particular rows from a database, and put them into the android's database into particular fields. I've tried modifying my JSONParser code to use BackgroundTask like this, and you can take a look at this.
This is what the project is trying to achieve: The first user can post a message to a server db whch contains 'from' (which would be user1's cell number), 'to' (which would be destination or user2's number), and a message (which is his location). The second user uses a polling service to periodically retrieve his messages from the database, i.e. all entries in the database where his number would be in the "to" field and store those entries into a database on his phone (and automatically delete those entries from the server's db). Everything is basically working, I think, except the part where I get particular entries from the server's db.
I decided to use JSONParsing because it can take an array of db entries and make a string out of each entry, making it easier to store in my android's db. But this is where it lacks..finding a way to retrieve particular entries of a db..I have not figured out a way to do this. Any help to point me into the right direction?
Sessions are designed to be unique for each visitor, this is done by remembering the session in a cookie. Your computer will have a different session to your Android. And in fact each browser on your computer will have a different session, unless they have a way of sharing cookies.
Furthermore, scripted requests (like Android code) do not automatically remember cookies and send between requests, and so they may start a new session for each request, and lose information from the previous session.
There are a number of solutions...
Restructure your process so that you do not need to retain the messages in this way - just returning the messages from the script that deletes them maybe? Or having the first script return messages and pass the second script the message IDs to delete. This last point might also be "safer" as you're not deleting anything until you know the app has received it.
Find a way to remember cookies and send them with subsequent requests. How do I make an http request using cookies on Android? might be useful for this.
Get the session ID from PHP and send it along with all your requests. You can get and set the session ID in PHP with session_id().
The last two are not great practice for APIs, as we aim for APIs to be stateless, but they may work for you.
Yeah i see the issue, thats odd i have not come across this before, but it appears you can add something to your SQL statement to correct it...
SELECT * FROM messages WHERE touser='$from' AND WHERE touser IS NOT NULL
I think that will prevent the null rows from showing. The IS NOT NULL should be the key.
I'm having problems with ldap search filters.
I want to search through all the children of a root node. I want the users where the username of the email contains the query string.
for example, if I have
foo_l.c_bar#foobar.com
foobar#foo_l.c_bar
and the search query is "l.c" I want only foo_l.c_bar#foobar.com
the following code, surprisingly, returns either the first and the second.
String query = "...";
DirContext dc = ...;
NamingEnumeration<SearchResult> ne = dc.search(root,
"(email=*{0}*#*)",
new Object[] { query }, null);
what's wrong in the "*...*#*" query filter?
I cannot give you a full answer, but if you try a ldapsearch from command line with the filter "(email=*l.c*#*)", you should get the right records ... so I would say the problem is in the Java method and not in the filter.
Hope it could help you.
I assume you forgot to paste the code that formatted your query and its {0} parameter ?
edit: wow, forget me, I didn't even know about the method that takes the filterArgs array.
As a side note, the standard attribute for e-mail address in inetOrgPerson is "mail" not "email" (but it might be different on your case of course)
I have a Java application, and use OJB as my ORM technology. I have an Oracle XE installation locally to develop against. The problem is when I need to debug a problem, I like looking at the SQL output. Here is an example of SQL I can view through the "Top SQL" interface in Oracle XE:
select a_bunch_of_fields
from KREW_DOC_TYP_T A0
WHERE ((UPPER(A0.DOC_TYP_NM) LIKE :1) AND A0.ACTV_IND = :2) AND A0.CUR_IND = :3
The problem is I would like to see the real value instead of ":1". I can't seem to find how I can configure this. I know the real values are working, because the application is responding as expected, for the most part (hence the bugs I am working on).
Thanks,
Jay
One quick and dirty way is to look in the provided database views (v$sql_bind_capture and v$sqlarea). In the SQL below, I just added a like clause to match the sql statement you have above, you will then get a row for each bind variable and it's value. To target a very specific SQL statement you want the sql_id for your query.
SELECT a.sql_text, b.NAME, b.POSITION, b.datatype_string, b.value_string
FROM v$sql_bind_capture b, v$sqlarea b
WHERE b.sql_id = a.sql_id
and a.sql_text like '%UPPER(A0.DOC_TYP_NM) LIKE :1%'
Output (without the SQL the result would look look something like this):
"NAME","POSITION","DATATYPE_STRING","VALUE_STRING"
":B1","2","NUMBER","1001"