Android :: Detect If A Table Contains A Column In Droid / Sqlite
Apr 20, 2010
So I have an app on the market, and with an update I want to add some columns to the database. No problems so far. But I want to detect if the database in use is missing these columns, and add them if this is the case. I need this to be done dynamically and not just after the update to the new version, because the application is supposed to still be able to import older databases. Normally I would be able to use the PRAGMA query, but Im not sure how to do this with Android. I cant use execSQL since it is a query, and I cant figure out how to use PRAGMA with the query()-function.
Ofcourse I could just catch exceptions and then add the column, or always add the columns to each table before I start to work with it, but that is not a neat solution.
View 4 Replies
Jul 29, 2010
I'm not big into UI programming so this may be an easy thing I overlooked. I am trying have a screen that shows 8 TextView in a 2 column x 4 row table. And, of course, I want the TextViews, that might have different lengths, to be centered. I tried this in a table layout, for obvious reasons but I feel like this is not the way to do it because it doesn't have much control where I put everything once it is in a row. Should I be using a different combinations of layouts or is there something I overlooked.
View 2 Replies
View Related
Nov 10, 2010
I'm attempting to create a method that will allow me to retrieve a value from the last row of a database, and then insert it into an EditText field. (This is a value that the user will not change all that often, so it would be helpful if when they do set it, it stays set when they come back to it).
My method, based on a similar method I have for getting the total of a specific column, is as such. code...
If I run the program without this statement, it works fine and the value saves to the db. As soon as I try to run it with this, I get a force close. Any suggestions?
View 2 Replies
View Related
Oct 11, 2010
How do i efficiently copy a row data from one table to another table, where both of them are the same structure. i could go the much harder way of retrieving initial values from the row in the first table and then inserting to the second table. But i feel there is a more efficient way this can be done.
View 1 Replies
View Related
Nov 23, 2010
can I insert a new column into existing table. Because I had read somewhere that SQLite is limited on the ALTER TABLE command.
View 2 Replies
View Related
Aug 3, 2010
I am trying to create a basic datasheet in my application using a TableLayout. The first row contains the titles of each column. Every row thereafter is data. I would like the data to be scrollable while keeping the first title row visible (i.e. the first row would not scroll with the rest).I have tried something like the following (unsuccessfully)
View 1 Replies
View Related
Nov 17, 2010
How to create a table without primary key but it has one autoincrement column.
View 2 Replies
View Related
Jul 22, 2010
I have a table with column headings: | _id (long) | Name (String) | x (integer) | y (integer) |
I want to delete the row in the table that has Name myName.
// In onCreate
dbHelper = new DBAdapter(this);
dbHelper.open()
// Function in DBAdapter class
public boolean deleteTitleGivenName(String myName)
{return dbHelper.delete(DATABASE_TABLE_2, KEY_NAME + "=" + myName, null) > 0;}
// Function call in java code
dbHelper.deleteTitleGivenName(myName); // this is where my code fails
dbHelper.close();
Just as a note: myName is for sure in the database. Also, I can not use the ROWID since I am getting myName from a ListView.
I just started programming with Android and I have tried for days to solve this problem.
Is my WHERE clause correct (KEY_NAME + "=" + myName)?
View 2 Replies
View Related
Mar 2, 2010
I am trying out this table layout in which there are three columns, each column utilizing the maximum space as they could (using strechColumn tag). Now when a column gets content which is too long, then table layout jumps of the screen.
How can i set the content of a column to wrap, so that table layout dont jump off the screen.
here is the XML code for table layout i used...
View 1 Replies
View Related
Feb 12, 2010
Suppose I have a view inside TableLayout, like this:
TableLayout tableLayout;
View view = (View)tableLayout.findViewById(R.id.control);
How can I find out the view's row/column within the TableLayout?
View 1 Replies
View Related
Jul 15, 2010
I have two files, one called "part1.txt" and another one called "part2.txt", which look like following
part1.txt part2.txt
lili like eating apple
lucy like playing football
Now i want to insert the contents of these two files into a single table with the schema
table_name(linefrompart1 varchar(100), linefrompart2 varchar(50))
My program reads the first file line by line and insert the data into the first column. But if it reads the second file and tries to insert the data line by line into the second column, it doesn't work the way i want. A table which i want should look like following
linefrompart1 linefrompart2
lili like eating apple
lucy like playing football
But instead i got the following table
linefrompart1 linefrompart2
lili null
lucy null
null like eating apple
null like playing football
Does somebody know how i can fix this problem?
View 1 Replies
View Related
Mar 9, 2010
Is it possible for my android application to dynamically adjust the no of column and no of row of my TableLayout based on orientation?
For example, when in landscape mode, the TableLayout is 3x2 and when
in portrait mode, the TableLayout is 2x3?
View 1 Replies
View Related
Nov 24, 2010
I have created a table named train_table in SQLite database with 3 columns. they are train_id, train_no and train_name. Now, i wrote a class in which i displayed the train_name in a list view. how do i get the related train_no in the next page? can anyone help me in sorting this problem.?
View 2 Replies
View Related
Jun 21, 2009
I am trying to utilize what has allready been written for this, in my own database
I will actually post my code so someone may be able to pick out what is wrong
This is the error i get: 06-21 19:57:35.511: ERROR/AndroidRuntime(796): Caused by:
code:................
This is the method its faulting on in Class:
code:..............................
View 2 Replies
View Related
May 4, 2010
Can I create index on a column in the create table command in sqlite?I tried this command below in sqlite3 in Android shell. It seems to work.But, in sqlite's query language specification, specifying a column to be indexed is not supported.
View 1 Replies
View Related
Oct 12, 2009
I have a database that I download external and save on my sdcard. But this database is also used for an iPhone app and has a column id and not _id (sqlite uses _id). How can i rename this column to _id?
View 4 Replies
View Related
Oct 7, 2009
I have a TEXT column and I want to match all rows where the value has a certain prefix. For example, WHERE mycol LIKE 'myprefix%' However, I noticed in some optimization guidelines that this will not use the index and instead you should do this:WHERE mycol >= 'myprefix' AND mycol < 'myprefiy'Instead of simple A-Z chars, I have a whole variety of UTF-8 chars (think chinese characters).My question is, how to work out the next char in UTF-8? Is it enough to add one to the codepoint,
View 3 Replies
View Related
May 8, 2010
I am trying to update a datetime column in an android sqlite db to use international date format (yyyy-mm-dd) instead of the current format (mm/dd/yyyy). I want to use the sqlite date() function to reformat the current value of the column. I thought it would be as simple as the following: update tblename set thedate = date(thedate)
But the above does not work.
How would i write the sql statement to accomplish this?
View 1 Replies
View Related
Jun 23, 2010
I'm working on an Android App where the user has different options for sorting the displayed data that comes from the database. Currently my orderBy string that I pass to Androids query() method looks like this:
"LOWER("+columnName+") ASC"
The problem with this is that if the data type in the column specified by columnName is integer, calling LOWER() on it will cause it to be sorted alphabetically, i.e. based only on the leftmost digit, which of course doesn't make any sense for numeric data. Hence I only want to apply LOWER() if the data type of the column is not integer. What I have in mind is a statement like this:
"CASE WHEN [data type of columnName is integer] THEN "+columnName+" ASC ELSE LOWER("+columName+") ASC END"
The part in the brackets is what I don't know how to do. Does SQLite provide a function to determine a column's data type?
View 3 Replies
View Related
Nov 13, 2010
I have decided that I hate SQL and for that purpose I am trying to make a helper class that I can reuse over and over and never have to mess with it again but it isnt working!
Here is what i have right now:
CODE:.........
I have included several System.out.println() statements to help me debug the code and find problems so please ignore them. PrintDB is another test that I wrote that I am using to make sure everything is working. Now this is what I have written to make sure everything is working....
CODE:.....................
Running this code everything goes great and all the System.out.println() statements have the right information in them until it gets to the databaseView.setText(db.printTable(tableName));
part and it throws an exception
CODE:................
This has me so confused because that same line of code is used in the getColNames() method that was called several times before this and ran with no problem. Also if the table didn't exist wouldn't it have thrown an exception when I called insertRow()? I called that method 5 times in a row with not a single exception thrown! What is happening here?
Implement onCreate() in your DBOpenHelper. Put there content of the createTable() method.
Why would it be necessary to create the table in the onCreate() method? If I were to do this would I be able to use my existing method to do so and just call it from this method?
And the second why you don't use content providers and uri >concept which is already SQLless?
View 1 Replies
View Related
Nov 23, 2010
This is my code used to create table code...
View 1 Replies
View Related
May 8, 2013
I am developing an application in android allowing the user to maintain his weight by providing him diet suggestions. I have done with that part and now, I need to display user weight tracking details using bar graph. I am able to fetch the Weight and Login date column data from the sqlite database to List<String>. I don't understand the way to put these values into a Bar Graph with Date Column data as X-axis and Weight column data as Y-axis.
View 1 Replies
View Related
Apr 6, 2010
In my game I am handling the loss of a character (represented programmatically with their own table) - however there are 4 such tables. I would like to know if there is a simple way to simply tell SQLite to make character 2's entire table equal character 3's? Just trying to not leave a gap in the lineup.
I was considering pulling all the data, sorting it out, putting it into the table and then deleting - I just wanted to know if there was a nifty shortcut to tell SQLite that I wanted to duplicate an entire table at another preexisting table?
http://defiledroid.wordpress.com/
View 4 Replies
View Related
Aug 8, 2010
I have a database with tables called box, item, and box_contents and I want to get any item that is contained in the box_content table (all items, but discard the ones that arent in the box_contents table). What would be the correct sqllite syntax for this?
View 2 Replies
View Related
Jun 22, 2010
The following function is giving me an out of bounds exception...
public void count(){
SQLiteDatabase db = table.getWritableDatabase();
String count = "SELECT count(*) FROM table";
Cursor mcursor = db.rawQuery(count, null);
int icount = mcursor.getInt(0);
System.out.println("NUMBER IN DB: " + icount);}
It's meant to return the number of rows in the database. Anybody know whats wrong? am I perhaps doing this task the wrong way?
View 2 Replies
View Related
Nov 14, 2011
i'm trying to access (read & write) from non-default (example 2nd table) table of a sqlite database which i created using sqlite database browser. but somehow, i cant seems to find the way to access it.
Code:
public class DatabaseHelper extends SQLiteOpenHelper {
private static String DB_PATH = "/data/data/com.sg/databases/";
private static String DB_NAME = "TestDatabase";
private SQLiteDatabase myDatabase;
[code]...
select data method works, but i can only select from table 1 and not table 2
View 4 Replies
View Related
May 22, 2010
In my project, I would like to create a database with single table. I would also like to insert data on this table from word or excel document. is it possible? if so please how can I do it? some code snippets would be of great help. I have four different activities which I would like them to interact with this single table. the first is the main activity and its purpose is just to launch the other three activities according to user choice. so it has no interaction with the DB. but the other three activities will read from the table whenever called. Can you please tell me how to call the dbhelper on these activities? I am unable to do this and I am currently creating one db per each activity which is not the optimal way.
View 1 Replies
View Related
Mar 21, 2012
I've a problem with a query in sqlite3.
The query is very simple:
SELECT MAX (INIT_DATE) INIT_DATE FROM TABLE;
When my application execute this query, and the table is empty, a record is returned. I can't understand why a record is being returned if the table is empty. It should return cero results.
I've tried to execute the query in two different ways:
cursor = db.query(true, "TABLE", new String[] {"MAX(INIT_DATE) AS INIT_DATE"}, null, null, null, null, null, null);
cursor = db.rawQuery("SELECT MAX(INIT_DATE) AS INIT_DATE FROM TABLE", null);
View 3 Replies
View Related
Aug 10, 2010
See title for explanation.
Here is the method I'm using:
CODE:.........
And here is the call to the method:
CODE:...........
Why it would be throwing the "No Column Found with name=Test", although my DB explorer shows there is indeed a column named name and a value in a row named Test?
View 1 Replies
View Related
Jul 14, 2010
I created a sql lite database with the following columns:
static final String dbName="demoDB";
static final String tableName="Employees";
static final String colID="EmployeeID";
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE "+tableName+" ("+colID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
colName+" TEXT, "+colAge+" Integer);");
I want to select all the records in the database like this and display them in a gridview:SQLiteDatabase db=this.getWritableDatabase();Cursor cur= db.rawQuery("Select "+colName+", "+colAge+" from "+tableName, new String [] {});String [] from=new String []{DatabaseHelper.colName,DatabaseHelper.colAge};
int [] to=new int [] {R.id.colName,R.id.colAge};
SimpleCursorAdapter sca=new SimpleCursorAdapter(this,R.layout.gridrow,c,from,to);
GridView grid=(GridView)findViewById(R.id.grid);
grid.setAdapter(sca);but i receive the following exception:java.lang.IllegalArgumentException: column '_id' does not exist.the db table does not have a column with name '_id'so what is wrong with this code
View 3 Replies
View Related