I give the user of my application the possibility to create an individual database table with specific values. So the user can define the tablename and the user can add specific values (like 'articlename', 'price', 'length') and so on to this tablename. The values can be chosen out of a list. When the user confirm the tablename and the values with a click onto a button, a new database table shall be create with the specific tablename and the specific values.
My problem is to read this individual table with this tablename, because the values of the database table aren't fix and the position of a value can be different.
What already works:
- the user can choose different values out of a list
- a new database table with the specific tablename and the specific values is creating
I know how to read values out of a database table, when the values are fix (valuename and position in database table). When they are fix I read the values with this code:
public String[] get_artikelgruppe () {
db = this.getWritableDatabase( );
String artikel_gruppen_id = "SELECT * FROM ARTIKELGRUPPEN";
Cursor artikel_gruppen_cursor = db.rawQuery( artikel_gruppen_id, null );
int artikel_gruppen_cursorCount = artikel_gruppen_cursor.getCount( );
Log.d( "count", "count " + artikel_gruppen_cursorCount );
String[] artikel_gruppen_string_array = new String[ artikel_gruppen_cursorCount ];
if ( artikel_gruppen_cursor.moveToFirst( ) ) {
if ( artikel_gruppen_cursor.isNull( 0 ) ) {
Log.d( "count2", "count2 " + artikel_gruppen_string_array );
return new String[]{ String.valueOf( new String[]{ String.valueOf( -1 ), "null" } ) };
}
// int id;
String name = "";
int i = 0;
do {
// id = artikel_gruppen_cursor.getInt( 0 );
name = artikel_gruppen_cursor.getString( 0 );
String current2 = name;
artikel_gruppen_string_array[ i ] = current2;
} while ( artikel_gruppen_cursor.moveToNext( ) );
}
return artikel_gruppen_string_array;
}
But how to modify this code to read individual values?
As you can see in my code snippet I can't write name = artikel_gruppen_cursor.getString( 0 ); in this case, because the Position in the tablename is unclear. And I don't know wheter the value 'name' is in this tablename.
Example:
- user define the tablename 'test01' and the values 'articlename' and 'price' -> a table with the tablename 'test01' and the values 'articlename' and 'price' is creating
- user define the tablename 'test02' and the values 'color', 'articlename' and 'width' -> a table with the tablename 'test02' and the values 'color', 'articlename' and 'width' is creating
I hope the Situation is clear enough.
Thanks a lot. Thanks a lot.
Aucun commentaire:
Enregistrer un commentaire