Six issues encountered when recovering an index (is there a lot of holes in the programming industry?) )

Source: Internet
Author: User

Six issues encountered when recovering an index:
1. Remember not to use external sqlite tools to open the observation database situation, look comfortable, debugging when you forget to close it, resulting in no matter how to shut down the database (rename file always fails)

2. Unzip to the current directory, which directory to write clearly (by default may be extracted into the directory of the executable file), but the extracted file name is not written, because the files in the compressed package is what name is the name of

3. You must wait until the M_database object disappears to remove the database
Http://doc.qt.io/qt-5/qsqldatabase.html#removeDatabase
If completely closed, qsqldatabase::removedatabase (strindex) may need to be executed; Otherwise there will be a name residue (the memory object should not remain)

But to get rid of this name, but also must after Qsqldatabase M_database disappears, but this is the class member form object, how disappears? Only one static function can be added free:
void Dbtool::free (dbtool* tool)
{
OO uses static functions to destroy objects, and it can do extra things that are stronger than simple delete
QString Strindex = tool->m_uniquename;
if (tool) {
Delete tool;
tool = NULL; OO CCC There is no point in initializing the incoming pointer, and the pointer itself is just a copy value
Qsqldatabase::removedatabase (Strindex);
Dbtool::m_dbnames.removeall (Strindex);
}
}
, you will not be able to use delete mydb in the future and must be used Dbtool::free (System::m_index).

4. Static variables must be initialized in the CPP file, even if the static variable itself is a variable (not a pointer), it still needs to be initialized, as follows:
Qstringlist Dbtool::m_dbnames;

5. There is no point in passing the pointer to a function and setting the pointer to null. It must be written like this:
if (System::m_index) {
Dbtool::free (System::m_index);
Delete System::m_index;
Qdebug () << system::m_index;
System::m_index = NULL;
}
Otherwise, the second click on the button, will try to delete an already nonexistent object, the program immediately crashes!

6. If the database has not been opened at all, it is necessary to submit data error. The usual error is because the problem is covered up. Therefore, to add to the current database connection is valid and open, to be judged:
Logtool::~logtool (void)
{
if (M_database.isvalid () && M_database.isopen ()) {
M_database.commit ();
M_database.close ();
}
}

For these few questions, depressed for a whole day, are ready to watch other posts, just suddenly enlightened (mainly the first problem). I'm an old hand, how come I've had so many problems ...

Six issues encountered when recovering an index (is there a lot of holes in the programming industry?) )

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.