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

Trying to use SQL

Im a new programmer to the android scene and im having trouble trying to create the table read from it and write to it.

I have experience with how PHP works and i know how to query but i am having trouble trying to understand how its created and the code behind it.

https://developer.android.com/training/basics/data-storage/databases.html

i went through this and i dont even understand it at all.

For example sake lets use this example query...

Creating Table
CREATE TestDB;

Creating Table
CREATE TABLE `TestDB`.`TestTable` ( `id` INT(10) NOT NULL AUTO_INCREMENT ,`user` VARCHAR(30) NOT NULL , `pass` VARCHAR(30) NOT NULL , `rank`ENUM('User','Admin','Owner') NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;

Pulling Info
SELECT * FROM TestTable WHERE id='1';

Update Info
UPDATE TestTable SET user=$user WHERE id='1';

These are queries i normally would use for php.

Could someone help me clarify how to translate this into android code?
 
Hi and welcome to Android Forums.
The link you included isn't a great place to start with databases in Android.
As it happens, Google have just released a new framework called 'Rooms', which simplifies database interaction. If you're new to it all, then I would take some time to learn how to use it. Rooms is an ORM (Object to Relational Mapping) layer, which allows you to save the state of objects (known as Entities) in your code. You don't have to deal directly with SQL queries, as this is handled by the framework.
You still can, if you wish, use SQL queries in the traditional way.
See here:

http://www.vogella.com/tutorials/AndroidSQLite/article.html
 
What in the hell is that shit.

Is there something more simpler like how you do it in PHP?

Because this is so much work just to do simple queries and a database. Im lost and i have no idea where to even begin. Just to create the data object is an entire script.
 
That's the shit you have to learn to work with databases in an android app. This is Java, not a script kiddie language like PHP.
 
Back
Top Bottom