Guest User

Untitled

a guest
Jul 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. package com.rough.problem.problem9;
  2.  
  3. import android.graphics.Color;
  4. import android.graphics.PorterDuff;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.widget.EditText;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12. EditText Select;
  13. DatabaseHelper myDB;
  14.  
  15.  
  16. @Override
  17.  
  18. protected void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.activity_main);
  21. myDB = new DatabaseHelper(this);
  22.  
  23. Select = (EditText) findViewById(R.id.SelectStatement);
  24.  
  25.  
  26. // Select.getBackground().setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
  27.  
  28. }
  29.  
  30.  
  31.  
  32. public boolean onCreateOptionMenu (Menu menu){
  33. getMenuInflater().inflate(R.menu.menu_main,menu);
  34. return true;
  35. }
  36.  
  37.  
  38. public boolean onOptionsItemSelected(MenuItem item){
  39. int id = item.getItemId();
  40. return true;
  41. }
  42. }
  43.  
  44. package com.rough.problem.problem9;
  45.  
  46. import android.content.ContentValues;
  47. import android.content.Context;
  48. import android.database.sqlite.SQLiteDatabase;
  49. import android.database.sqlite.SQLiteOpenHelper;
  50.  
  51.  
  52.  
  53. public class DatabaseHelper extends SQLiteOpenHelper {
  54. public static final String DATABASE_NAME = "SPdb.db";
  55. public static final String TABLE_NAME = "s";
  56. public static final String COL_1 = "sno";
  57. public static final String COL_2 = "sname";
  58. public static final String COL_3 = "city";
  59.  
  60.  
  61. public static final String TABLENAME = "p";
  62. public static final String COL1 = "pno";
  63. public static final String COL2 = "pname";
  64. public static final String COL3 = "cost";
  65. public static final String COL4 = "city";
  66.  
  67. public static final String TableNAME = "sp";
  68. public static final String COLUMN1 = "sno";
  69. public static final String COLUMN2 = "pno";
  70. public static final String COLUMN3 = "qty";
  71.  
  72.  
  73.  
  74.  
  75. public DatabaseHelper(Context context) {
  76. super(context, DATABASE_NAME, null, 1);
  77. SQLiteDatabase db = this.getWritableDatabase();
  78.  
  79. }
  80.  
  81.  
  82. @Override
  83. public void onCreate(SQLiteDatabase db) {
  84. String query = "Create Table IF NOT EXISTS " + TABLE_NAME + "(" +
  85. COL_1 + "TEXT PRIMARY KEY COLLATE NOCASE," +
  86. COL_2 + "TEXT NOT NULL COLLATE NOCASE," +
  87. COL_3 + "TEXT NOT NULL COLLATE NOCASE" +
  88. ");";
  89. db.execSQL(query);
  90.  
  91. String query1 = "Create Table IF NOT EXISTS " + TABLENAME + "(" +
  92. COL1 + "TEXT NOT NULL COLLATE NOCASE," +
  93. COL2 + "TEXT NOT NULL COLLATE NOCASE," +
  94. COL3 + "REAL NOT NULL ," +
  95. COL4 + "TEXT NOT NULL COLLATE NOCASE" +
  96. ");";
  97. db.execSQL(query1);
  98.  
  99. String query2 = "Create Table IF NOT EXISTS " + TableNAME + "(" +
  100. COLUMN1 + "TEXT NOT NULL REFERENCES s(sno) COLLATE NOCASE," +
  101. COLUMN2 + "TEXT NOT NULL COLLATE NOCASE," +
  102. COLUMN3 + "INTEGER NOT NULL " +
  103. ");";
  104. db.execSQL(query2);
  105. }
  106.  
  107. @Override
  108. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  109.  
  110. db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
  111. onCreate(db);
  112. }
  113.  
  114. /*public void insertData(String sno, String sname, String city){
  115. SQLiteDatabase db = this.getWritableDatabase();
  116. ContentValues contentValues = new ContentValues();
  117. ContentValues values = new ContentValues();
  118. values.put(COL_1, "S01");
  119. values.put(COL_2 , "Smith");
  120. values.put(COL_3 , "London");
  121. db.insert(TABLE_NAME, null, values);
  122.  
  123. } */
  124. }
Add Comment
Please, Sign In to add comment