Problems with SQLite [closed]

-1

Good afternoon, I just try to translate and know what the example codes say in order to better understand how everything works, and get stuck in this fregmentom, it is part of a code for a database with multi table in android studio , the code is the following ..

(I take everything out of this exercise link and my intention is to learn to do multitablas database in sqlite for android studio UU)

I want to know what it does or what it means and how the line is read, which is the getSimpleName(); ?

public static final String TAG = Course.class.getSimpleName();

in this class

package com.instinctcoder.sqlitedbmultitbl.data.model;

/**
* Created by Tan on 1/26/2016.
*/
public class Course {

public static final String TAG = Course.class.getSimpleName();
public static final String TABLE = "Course";
// Labels Table Columns names
public static final String KEY_CourseId = "CourseId";
public static final String KEY_Name = "Name";

private String courseId;
private String name;


public String getCourseId() {
    return courseId;
}

public void setCourseId(String courseId) {
    this.courseId = courseId;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}
}

and then ... in this block I do not know the guys " data.repo " who then uses them as ...

    db.execSQL(CourseRepo.createTable());
    db.execSQL(StudentRepo.createTable());
    db.execSQL(MajorRepo.createTable());
    db.execSQL(StudentCourseRepo.createTable());

in the class ..

package com.instinctcoder.sqlitedbmultitbl.data;

/**
 * Created by Tan on 1/26/2016.
 */
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.instinctcoder.sqlitedbmultitbl.app.App;
import com.instinctcoder.sqlitedbmultitbl.data.model.Course;
import com.instinctcoder.sqlitedbmultitbl.data.model.Major;
import com.instinctcoder.sqlitedbmultitbl.data.model.Student;
import com.instinctcoder.sqlitedbmultitbl.data.model.StudentCourse;
import com.instinctcoder.sqlitedbmultitbl.data.repo.CourseRepo;
import com.instinctcoder.sqlitedbmultitbl.data.repo.MajorRepo;
import com.instinctcoder.sqlitedbmultitbl.data.repo.StudentCourseRepo;
import com.instinctcoder.sqlitedbmultitbl.data.repo.StudentRepo;


public class DBHelper  extends SQLiteOpenHelper {
//version number to upgrade database version
//each time if you Add, Edit table, you need to change the
//version number.
private static final int DATABASE_VERSION =8;
// Database Name
private static final String DATABASE_NAME = "sqliteDBMultiTbl.db";
private static final String TAG = DBHelper.class.getSimpleName().toString();

public DBHelper( ) {
    super(App.getContext(), DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    //All necessary tables you like to create will create here
    db.execSQL(CourseRepo.createTable());
    db.execSQL(StudentRepo.createTable());
    db.execSQL(MajorRepo.createTable());
    db.execSQL(StudentCourseRepo.createTable());
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.d(TAG, String.format("SQLiteDatabase.onUpgrade(%d -> %d)", oldVersion, newVersion));

    // Drop table if existed, all data will be gone!!!
    db.execSQL("DROP TABLE IF EXISTS " + Course.TABLE);
    db.execSQL("DROP TABLE IF EXISTS " + Student.TABLE);
    db.execSQL("DROP TABLE IF EXISTS " + Major.TABLE);
    db.execSQL("DROP TABLE IF EXISTS " + StudentCourse.TABLE);
    onCreate(db);
}

} 
    
asked by ERny JOsé HIdalgo COrrea 03.12.2016 в 03:23
source

2 answers

0

The instruction CualquierClase.class.getSimpleName() returns the name of the class as a String (in your case "Course" ), there is another function called getName that gets the full name of the class, that is, the name of the package plus the name of the class (In your case "com.instinctcoder.sqlitedbmultitbl.data.model.Course" ). This has nothing to do with sqlite, it's part of the java standard.

The variable TAG used in your code receives that value, since afterwards you use it as a means of debugging with the following instruction:

Log.d(TAG,..)

This last expression will allow you to read the information that you put in the execution time of the program. In your case you have the following code in the onUpgrade method that is executed when you update the database version:

Log.d(TAG, String.format("SQLiteDatabase.onUpgrade(%d -> %d)", oldVersion, newVersion));

This will print the values of the previous version and new version.

    
answered by 03.12.2016 / 05:24
source
0
  

what is the getSimpleName ();?

     

getSimpleName () : Returns the simple name of the class   underlying as indicated in the source code. Returns a string   empty if the underlying class is anonymous.

In this case you simply get the name of the class to be used as a label when printing data within LogCat :

public static final String TAG = Course.class.getSimpleName();

In this case it is the same as if you simply wrote:

public static final String TAG ="Course";
    
answered by 03.12.2016 в 08:24