Beispiel #1
0
QSqlQuery dbConnection::dbDelete(){
    QSqlQuery dbDelete(connectDb());
    dbDelete.prepare("DELETE FROM Kontak WHERE Pin = :Pin");
    dbDelete.bindValue(":Pin", getDelete());
    dbDelete.exec();
    connectDb().close();
    return dbDelete;
}
Beispiel #2
0
QSqlQuery dbConnection::dbInsert(){
    QSqlQuery dbInsert(connectDb());
    dbInsert.prepare("INSERT INTO Kontak(Nama, Pin, Jenis_Kelamin) VALUES (:Nama, :Pin, :Jenis_Kelamin)");
    dbInsert.bindValue(":Nama", getNama());
    dbInsert.bindValue(":Pin", getPin());
    dbInsert.bindValue(":Jenis_Kelamin", getKelamin());
    dbInsert.exec();
    connectDb().close();
    return dbInsert;
}
Beispiel #3
0
bool dbConnection::dbConnect()
{
    if (!connectDb().open()) {
            return false;
        }
    else{
            connectDb().close();
            return true;
    }
}
Beispiel #4
0
int main(){
	
	connectDb(p::db);

	connectSocket(p::mysocket);

	char ipClient[32] = "\0";
	ODSocket clientsocket;
	
	while(true){
		bool isAccpet = p::mysocket.Accept(clientsocket,ipClient);
		if (isAccpet)
		{
			printf("connect ip = %s",ipClient);
			std::thread new_thread(TalkToClient,&clientsocket,ipClient);
			new_thread.detach();
		}
		std::this_thread::sleep_for(std::chrono::milliseconds(50));
	}
	
 
#ifdef _WIN32
	p::mysocket.Close();
	p::mysocket.Clean();
	 
#endif
}
void QgsBookmarks::on_btnUpdate_clicked()
{
  // get the current item
  QTreeWidgetItem *item = lstBookmarks->currentItem();
  if ( item )
  {
    // make sure the user really wants to update this bookmark
    if ( QMessageBox::Ok == QMessageBox::information( this, tr( "Really Update?" ),
         tr( "Are you sure you want to update the %1 bookmark?" ).arg( item->text( 0 ) ),
         QMessageBox::Ok | QMessageBox::Cancel ) )
    {
      // retrieve the current map extent
      QgsRectangle viewExtent = QgisApp::instance()->mapCanvas()->extent();

      int rc;
      QgsDebugMsg( QString( "Opening user database: %1" ).arg( QgsApplication::qgisUserDbFilePath() ) );
      rc = connectDb();
      if ( SQLITE_OK == rc )
      {
        // prepare the sql statement
        QString sql;
        QTextStream sqlStream( &sql );
        // use '17 g' format; SmartNotation is default
        sqlStream.setRealNumberPrecision( 17 );
        sqlStream << "update tbl_bookmarks set " <<
        "xmin=" << viewExtent.xMinimum() << "," <<
        "ymin=" << viewExtent.yMinimum() << "," <<
        "xmax=" << viewExtent.xMaximum() << "," <<
        "ymax=" << viewExtent.yMaximum() << " " <<
        "where bookmark_id=" << item->text( 3 );
        QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );

        char * errmsg;
        rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg );
        if ( rc != SQLITE_OK )
        {
          // XXX Provide popup message on failure?
          QMessageBox::warning( this, tr( "Error updating bookmark" ),
                                tr( "Failed to update the %1 bookmark. The database said:\n%2" )
                                .arg( item->text( 0 ) ).arg( errmsg ) );
          sqlite3_free( errmsg );
        }
        // close the database
        sqlite3_close( db );

        refreshBookmarks();

      }
      else
      {
        QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( db ) ) );

        // XXX This will likely never happen since on open, sqlite creates the
        //     database if it does not exist.
        assert( rc == 0 );
      }
    }
  }
}
// Initialise the bookmark tree from the database
void QgsBookmarks::initialise()
{
  int rc = connectDb();
  if ( rc == SQLITE_OK )
  {
    // prepare the sql statement
    const char *pzTail;
    sqlite3_stmt *ppStmt;
    QString sql = "select * from tbl_bookmarks";

    rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail );
    // XXX Need to free memory from the error msg if one is set
    if ( rc == SQLITE_OK )
    {
      // get the first row of the result set
      while ( sqlite3_step( ppStmt ) == SQLITE_ROW )
      {
        QTreeWidgetItem *item = new QTreeWidgetItem( lstBookmarks );
        QString name = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 1 ) );
        //        sqlite3_bind_parameter_index(ppStmt, "name"));
        //QgsDebugMsg("Bookmark name: " + name.toLocal8Bit().data());
        item->setText( 0, name );
        // set the project name
        item->setText( 1, QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 2 ) ) );
        // get the extents
        QString xMin = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 3 ) );
        QString yMin = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 4 ) );
        QString xMax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 5 ) );
        QString yMax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 6 ) );
        // set the extents
        item->setText( 2, xMin + ", " + yMin + " : " + xMax + ", " + yMax );   // use colon to separate ll from ur corners listed (be consistent with other displays of extent)
        // set the id
        item->setText( 3, QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) );
      }
      for ( int col = 0; col < 4; col++ )
      {
        lstBookmarks->resizeColumnToContents( col );
      }
      lstBookmarks->sortByColumn( 0, Qt::AscendingOrder );
    }
    else
    {
      // XXX query failed -- warn the user some how
      QgsDebugMsg( QString( "Failed to get bookmarks: %1" ).arg( sqlite3_errmsg( db ) ) );
    }
    // close the statement
    sqlite3_finalize( ppStmt );
    // close the database
    sqlite3_close( db );
    // return the srs wkt

  }
}
Beispiel #7
0
Quest::Quest(QString tsk, QString endTask, int id) {
    quest_id = id;
    progress = 0;
    show_status = false;

    texture.loadFromFile("Media/text.png");
    sprite.setTexture(texture);

    award_texture.loadFromFile("Media/lvlup.png");
    award_sprite.setTexture(award_texture);

    font.loadFromFile("Media/font1.ttf");
    txt_font.loadFromFile("Media/font1.ttf");
    text.setFont(txt_font);
    text.setColor(sf::Color::Cyan);
    text.setCharacterSize(30);

    task.setFont(font);
    task.setColor(sf::Color::Blue);
    task.setCharacterSize(30);
    task.setString(tsk.toStdString());

    QSqlDatabase gamedb;

    if(connectDb(gamedb))
        qDebug() << "Connected to database";
    else
        qDebug() << "Error opening database!";


    QSqlQuery query(gamedb);

    query.prepare("SELECT * FROM quests WHERE id = :id");
    query.bindValue(":id", quest_id);

    if(query.exec()){
         while(query.next()) {
             owner_id = query.value(1).toString().toInt();
             unit_id = query.value(2).toString().toInt();
             gold_award = query.value(3).toString().toInt();
             exp_award = query.value(4).toString().toInt();
             type = query.value(5).toString().toInt();
         }
    }

    end = endTask;
    //show_quest = false;
}
void QgsBookmarks::zoomToBookmark()
{
  // Need to fetch the extent for the selected bookmark and then redraw
  // the map
  // get the current item
  QTreeWidgetItem *item = lstBookmarks->currentItem();
  if ( !item )
  {
    return;
  }
  // get the extent from the database
  int rc = connectDb();
  if ( rc == SQLITE_OK )
  {
    sqlite3_stmt *ppStmt;
    const char *pzTail;
    // build the sql statement
    QString sql = "select xmin, ymin, xmax, ymax from tbl_bookmarks where bookmark_id = " + item->text( 3 );
    rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail );
    if ( rc == SQLITE_OK )
    {
      if ( sqlite3_step( ppStmt ) == SQLITE_ROW )
      {
        // get the extents from the resultset
        QString xmin  = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) );
        QString ymin  = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 1 ) );
        QString xmax  = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 2 ) );
        QString ymax  = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 3 ) );
        // set the extent to the bookmark
        QgisApp::instance()->setExtent( QgsRectangle( xmin.toDouble(),
                                        ymin.toDouble(),
                                        xmax.toDouble(),
                                        ymax.toDouble() ) );
        // redraw the map
        QgisApp::instance()->mapCanvas()->refresh();
      }
    }

    // close the statement
    sqlite3_finalize( ppStmt );
    // close the database
    sqlite3_close( db );
  }

}
void QgsHelpViewer::loadContextFromSqlite( const QString &contextId )
{
  if ( contextId != QString::null )
  {
    // connect to the database
    QString helpDbPath = QgsApplication::pkgDataPath() + "/resources/qgis_help.db";
    int rc = connectDb( helpDbPath );
    // get the help content and title from the database

    if ( rc == SQLITE_OK )
    {
      sqlite3_stmt *ppStmt;
      const char *pzTail;
      // build the sql statement
      QString sql = "select content,title from context_helps where context = '" + contextId + "'";
      rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail );
      if ( rc == SQLITE_OK )
      {
        if ( sqlite3_step( ppStmt ) == SQLITE_ROW )
        {
          // there should only be one row returned
          // Set the browser text to the record from the database
          webView->setHtml(( char* )sqlite3_column_text( ppStmt, 0 ) );
          setWindowTitle( tr( "Quantum GIS Help - %1" ).arg(( char* )sqlite3_column_text( ppStmt, 1 ) ) );
        }
      }
      else
      {
        QMessageBox::critical( this, tr( "Error" ),
                               tr( "Failed to get the help text from the database:\n  %1" )
                               .arg( sqlite3_errmsg( db ) ) );
      }
      // close the statement
      sqlite3_finalize( ppStmt );
      // close the database
      sqlite3_close( db );
    }
  }
}
void QgsBookmarks::on_btnDelete_clicked()
{
  // get the current item
  QTreeWidgetItem *item = lstBookmarks->currentItem();
  if ( item )
  {
    // make sure the user really wants to delete this bookmark
    if ( QMessageBox::Ok == QMessageBox::information( this, tr( "Really Delete?" ),
         tr( "Are you sure you want to delete the %1 bookmark?" ).arg( item->text( 0 ) ),
         QMessageBox::Ok | QMessageBox::Cancel ) )
    {
      // remove it from the listview
      item = lstBookmarks->takeTopLevelItem( lstBookmarks->indexOfTopLevelItem( item ) );
      // delete it from the database
      int rc = connectDb();
      if ( rc == SQLITE_OK )
      {
        char *errmsg;
        // build the sql statement
        QString sql = "delete from tbl_bookmarks where bookmark_id = " + item->text( 3 );
        rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg );
        if ( rc != SQLITE_OK )
        {
          // XXX Provide popup message on failure?
          QMessageBox::warning( this, tr( "Error deleting bookmark" ),
                                tr( "Failed to delete the %1 bookmark from the database. The database said:\n%2" )
                                .arg( item->text( 0 ) ).arg( errmsg ) );
          sqlite3_free( errmsg );
        }
        // close the database
        sqlite3_close( db );
      }
      delete item;
    }
  }
}
Beispiel #11
0
void SQLThread::run()
{
    bool haveError = false;
    int tryCnt = 3;
    while(true)
    {
        while(rarelyUsed.empty() && frequentUsed.empty())
        {
            usedSemaphore.acquire();
            if(exitFlag)
            {
                rarelyUsed.clear();
                frequentUsed.clear();
                return;
            }
        }

        if(!rarelyUsed.empty())
        {
            //连接数据库
            if( rarelyUsed.front().task == ConnectDb)
            {
                 sql.setDb("test", rarelyUsed.front().user,
                           rarelyUsed.front().passwd);
                 if(!sql.openDb())
                 {
                    emit openError("Can not open the MYSQL database, please cheack...");
                    if(++tryCnt <= 3)
                    {
                        connectDb("test", rarelyUsed.front().user,
                                  rarelyUsed.front().passwd);
                    }
                    else
                        haveError = true;
                    break;
                 }

                 if(!sql.createDb(rarelyUsed.front().name))
                 {
                    emit openError("Create database failure....");
                    break;
                 }

                 if(!sql.changeDb(rarelyUsed.front().name))
                 {
                     emit openError("Change database failure....");
                     break;
                 }

            }
            else if( rarelyUsed.front().task == CreatTable)
            {
                if(! sql.createTable(rarelyUsed.front().name))
                {
                    emit openError("Create table failure....");
                    break;
                }
            }
             else if( rarelyUsed.front().task == SelectData)
            {

                emit getResult(sql.selectTable(rarelyUsed.front().name, cnt), cnt);
            }
            rarelyUsed.pop_front();
            freeSemaphore.release();
            continue;
        }
        //处理第二队列
        if(!frequentUsed.empty())
        {
            sql.insertData(frequentUsed.front().table,
                           frequentUsed.front().id, frequentUsed.front().data);
            frequentUsed.pop_front();
            freeSemaphore.release();
        }
    }
}