How to find a table exists or not?

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

How to find a table exists or not?

Postby jayaram » Wed Jul 29, 2009 12:55 pm

I want to know whether a particular table exists in my SQLiteDatabase or not, programmatically.
Is there any method to do that?
jayaram
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jul 29, 2009 3:37 am
Location: India

Top

Postby nmc » Wed Jul 29, 2009 6:32 pm

If you want to know that because you want to create the table if it doesnt exists, use
create table if not exist neededTable (...)


If you want to know that for any other reason, use

select name from sqlite_master where name='neededTable'


and fetch the result: 0: does not exist, 1: exists
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

How can i fetch an integer?

Postby jayaram » Thu Jul 30, 2009 9:07 am

The select query will return a cursor. How can i fetch an integer result from it?
Pls make it clear.
jayaram
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jul 29, 2009 3:37 am
Location: India

Postby nmc » Thu Jul 30, 2009 10:31 am

You dont know how to use a database-cursor? :shock:
Why do you want to know about the existence of a database-table if you dont know how to work with it?

:arrow: read the docs.
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Getting error with getCount()

Postby jayaram » Thu Jul 30, 2009 5:23 pm

I used cursor.getCount() method to find the number of rows in the cursor. But, i get 'cannot find symbol' error for getCount() method.
jayaram
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jul 29, 2009 3:37 am
Location: India

Postby nmc » Thu Jul 30, 2009 9:01 pm

Try using cursor.moveToFirst() prior to the cursor.getCount() call :)
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests