SQLite Schema Information Metadata

后端 未结 7 1032
终归单人心
终归单人心 2020-11-27 03:46

I need to get column names and their tables in a SQLite database. What I need is a resultset with 2 columns: table_name | column_name.

In MySQL, I\'m a

7条回答
  •  北海茫月
    2020-11-27 04:14

    This is an old question but because of the number of times it has been viewed we are adding to the question for the simple reason most of the answers tell you how to find the TABLE names in the SQLite Database WHAT DO YOU DO WHEN THE TABLE NAME IS NOT IN THE DATABASE ? This is happening to our app because we are creating TABLES programmatically So the code below will deal with the issue when the TABLE is NOT in or created by the Database Enjoy

        public void toPageTwo(View view){
    
        if(etQuizTable.getText().toString().equals("")){
            Toast.makeText(getApplicationContext(), "Enter Table Name\n\n"
                    +"           OR"+"\n\nMake Table First", Toast.LENGTH_LONG 
       ).show();
            etQuizTable.requestFocus();
            return;
        }
    
        NEW_TABLE = etQuizTable.getText().toString().trim();
        db = dbHelper.getWritableDatabase();
        ArrayList arrTblNames = new ArrayList<>();
        Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE 
       type='table'", null);
    
        if (c.moveToFirst()) {
            while ( !c.isAfterLast() ) {
                arrTblNames.add( c.getString( c.getColumnIndex("name")) );
                c.moveToNext();
            }
        }
        c.close();
        db.close();
    
        boolean matchFound = false;
        for(int i=0;i

提交回复
热议问题