×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    323

    Question How to check Table already exist or not

    Dear all,

    Any one can help me how to check that table already exist or not

    for eg:
    if its already exist it doesn't want to enter the value.

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to check Table already exist or not

    I guess your question is about SQL. You can do something like this
    Code:
    if object_id('table_name') is null create table 'table_name' ...
    Last edited by divanov; 2010-05-27 at 13:30. Reason: fixing wrong condition

  3. #3
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to check Table already exist or not

    What kind of table? Where?

  4. #4
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    323

    Question Re: How to check Table already exist or not

    Dear danhicksbyron,

    here is my below code i am calling SettingsScreenTable() in main Consuctor
    so when ever i am calling the consuctor its inserting 1 value in the table.
    for avoid that i created another function InsertIntialValue();

    But in that if condition executing only else condition even first time also
    ?

    Code:
    void DBConnect::SettingsScreenTable()
    {
        // Create table
      
        if (db.isOpen()) 
        	{
    			QSqlQuery query;
    			query.exec("create table SettingTable "
    				"(CheckValue integer )");
    			
    			query.exec("insert into SettingTable values(1)");
        	}
        //InsertIntialValue();
       
    }
    
    
    void DBConnect::InsertIntialValue()
    {
    	
    	QSqlQuery query;
    	query.exec(QString("Select CheckValue from SettingTable"));
    	int author;
    		 if ( query.next() )
    			 {
    			    author = query.value( 0 ).toInt();
    			 }
    		 if(author == NULL)
    			 {
    				 query.exec("insert into SettingTable values(1)");
    			 }
    		 else
    			 {
    				 CEikonEnv::InfoWinL(_L("Dont"),_L("Insert Value"));
    			 }
    }

  5. #5
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to check Table already exist or not

    You can find out which tables exist with
    Code:
    QStringList tables = db.tables();

  6. #6
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    323

    Question Re: How to check Table already exist or not

    Quote Originally Posted by danhicksbyron View Post
    You can find out which tables exist with
    Code:
    QStringList tables = db.tables();
    thx danhicksbyron, can u possible to check my previous thread and
    tell me why if condition is not working properly.

  7. #7
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to check Table already exist or not

    Could it be something like this?
    Code:
    void DBConnect::SettingsScreenTable()
    {
        int author = 0;
        if (!db.tables().contains("SettingTable")) {
            QSqlQuery query;
            query.exec("create table SettingTable (CheckValue integer )");
        } else {
            QSqlQuery query;
            query.exec(QString("Select CheckValue from SettingTable"));
            if (query.next()) {
                author = query.value(0).toInt();
            }
        }
        if(author == 0) {
            query.exec("insert into SettingTable values(1)");
        } else {
           int ret = QMessageBox::question(this, tr("Hello"),
                                    tr("What is the purpose of this information window?"),
                                    QMessageBox::Ok | QMessageBox::Cancel,
                                    QMessageBox::Ok);
        }
    }

  8. #8
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    323

    Thumbs up Re: How to check Table already exist or not

    Quote Originally Posted by divanov View Post
    Could it be something like this?
    thx divanov
    Last edited by damodharan; 2010-05-29 at 05:58.

Similar Threads

  1. Check if contact group exist?
    By MDanielsson in forum Symbian
    Replies: 17
    Last Post: 2009-01-21, 05:01
  2. S60 2nd to 3rd/ PlatformSecurity / Capabilities
    By jarkoos in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 4
    Last Post: 2007-04-14, 14:08
  3. Replies: 0
    Last Post: 2005-10-31, 20:05
  4. Showing check box on menu
    By Utk in forum Symbian
    Replies: 0
    Last Post: 2004-12-20, 07:52
  5. GSM/GPRS Drivers check FAILED
    By hblume in forum Multimodecards
    Replies: 3
    Last Post: 2004-01-28, 21:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×