initial import

This commit is contained in:
Mo Elzubeir
2022-12-13 09:18:00 -06:00
commit d2d561810c
322 changed files with 1147261 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
[master database]
server=localhost ;url for the database
port=3306
database=socialhose
uid=root
pwd=aq19911
[slave database]
server=localhost ;url for the database
port=3306
database=socialhose
uid=root
pwd=aq19911
[ftp access]
useftp=0 ;if set to 0, then no ftp will be used, otherwise, ftp upload is the default
server=localhost
port=21
username=aa
password=aq19911
+20
View File
@@ -0,0 +1,20 @@
[master database]
server=localhost ;url for the database
port=3306
database=socialhose
uid=root
pwd=aq19911
[slave database]
server=localhost ;url for the database
port=3306
database=socialhose
uid=root
pwd=aq19911
[ftp access]
useftp=0 ;if set to 0, then no ftp will be used, otherwise, ftp upload is the default
server=localhost
port=21
username=aa
password=aq19911
+13
View File
@@ -0,0 +1,13 @@
#include <QtGui/QApplication>
#include "sqldialog.h"
#include <QTextCodec>
int main(int argc, char *argv[])
{
//QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8") );
QApplication a(argc, argv);
SQLDialog w;
w.show();
return a.exec();
}
+20
View File
@@ -0,0 +1,20 @@
[master database]
server=localhost ;url for the database
port=3306
database=socialhose
uid=root
pwd=aq19911
[slave database]
server=localhost ;url for the database
port=3306
database=socialhose
uid=root
pwd=aq19911
[ftp access]
useftp=0 ;if set to 0, then no ftp will be used, otherwise, ftp upload is the default
server=localhost
port=21
username=aa
password=aq19911
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
CREATE TABLE `sample_page_text` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`pageText` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=821 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+18
View File
@@ -0,0 +1,18 @@
#-------------------------------------------------
#
# Project created by QtCreator 2010-02-05T18:33:30
#
#-------------------------------------------------
QT += sql
TARGET = sqlit_test
TEMPLATE = app
SOURCES += main.cpp\
sqldialog.cpp
HEADERS += sqldialog.h
FORMS += sqldialog.ui
+193
View File
@@ -0,0 +1,193 @@
#include "sqldialog.h"
#include "ui_sqldialog.h"
#include <QtSQL>
#include <QFileDialog>
#include <QTextEncoder>
SQLDialog::SQLDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::SQLDialog)
{
//QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates) );
ui->setupUi(this);
readSettings();
connectToDB();
}
SQLDialog::~SQLDialog()
{
delete ui;
}
void SQLDialog::readSettings()
{
QString config = QApplication::applicationDirPath()+ "/config.ini";
QSettings settings(config, QSettings::IniFormat);
m_masterDatabaseHost = settings.value("master database/server").toString(); //read master database's server value from settings
m_masterDatabaseName = settings.value("master database/database").toString(); //read master database's database name value from settings
m_masterDatabaseUser = settings.value("master database/uid").toString(); //read master database's user id value from settings
m_masterDatabasePassword = settings.value("master database/pwd").toString(); //read master database's password value from settings
m_masterDatabasePort = settings.value("master database/port").toInt(); //read master database's port value from settings
}
void SQLDialog::connectToDB()
{
m_masterDatabase = QSqlDatabase::addDatabase("QMYSQL", "master");
// initalize the connection
m_masterDatabase.setHostName(m_masterDatabaseHost);
m_masterDatabase.setPort(m_masterDatabasePort);
m_masterDatabase.setDatabaseName(m_masterDatabaseName);
m_masterDatabase.setUserName(m_masterDatabaseUser);
m_masterDatabase.setPassword(m_masterDatabasePassword);
// try to open the connection, if ok returns true, else returns false
bool ok = m_masterDatabase.open();
if(!ok)
{
// if error, get the error from the database text and print it to debug screen
QString str = m_masterDatabase.lastError().databaseText();
QMessageBox::critical(this, tr("Database Error"), tr("Error connecting to master database\n") + str);
}
}
void SQLDialog::on_pushButton_clicked()
{
QSqlQuery query(m_masterDatabase);
QString qtext = QString("INSERT INTO sample_page_text ( pageText ) VALUES (\"%1\")").arg(fileContent);
if( !query.exec( qtext ) ) //try it also query.exec(qtext);
{
QMessageBox::information(this, "Error inserting to database", query.lastError().text());
qDebug () << qtext;
}
}
void SQLDialog::on_pushButton_2_clicked()
{
fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
".",
tr("All (*.*)"));
if(fileName.isNull())
return;
//read the file
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
//in.setCodec("UTF-8");
fileContent = in.readAll();
file.close();
qDebug() << fileContent;
QFile file2(fileName+"_sample");
if (!file2.open(QIODevice::WriteOnly| QIODevice::Text))
return;
QTextStream out(&file2);
//out.setCodec("UTF-8");
out << fileContent;
file2.close();
fileContent.remove("\"");
fileContent.remove("'");
//fileContent.remove("\n");
ui->pushButton->setEnabled(true);
}
void SQLDialog::on_pushButton_3_clicked()
{
QSqlQuery query(m_masterDatabase);
QString qtext = "select name_searchword from searchword where id_company = 1125";
if( !query.exec( qtext ) ) //try it also query.exec(qtext);
{
QMessageBox::information(this, "Error database", query.lastError().text());
qDebug () << qtext;
return;
}
while(query.next())
{
QString str = query.value(0).toString();
qDebug() << str;
}
}
void SQLDialog::on_pushButton_4_clicked()
{
QString searchword = "ÏÈí";
QSqlQuery query(m_masterDatabase);
//query.prepare("SELECT cm.id_company, name_company, cm.desc_company, cm.towrite FROM company AS cm, searchword AS sw WHERE name_searchword LIKE :name AND sw.id_company = cm.id_company AND cm.date_end > NOW()"
// " UNION SELECT id_company, name_company, desc_company, towrite FROM company WHERE name_company LIKE :name2 AND date_end > NOW()");
query.prepare("SELECT cm.id_company, name_searchword FROM company AS cm, searchword AS sw WHERE sw.id_company = cm.id_company AND cm.date_end > NOW()");
//query.bindValue(":name", searchword);
//query.bindValue(":name2", searchword);
if ( !query.exec() )
{
qDebug() << "searchTags() SQL Error: " << query.lastError().text().toAscii();
qDebug() << "Executed Query: " << query.executedQuery().toAscii();
}
while(query.next())
{
qDebug() << query.value(0).toString();
qDebug() << query.value(1).toString();
//qDebug() << query.value(2).toString();
}
}
void SQLDialog::on_pushButton_5_clicked()
{
QSqlQuery query(m_masterDatabase);
query.prepare("SELECT `text` FROM page_text");
if ( !query.exec() )
{
qDebug() << "Executed Query: " << query.executedQuery().toAscii();
}
QString str;
while(query.next())
{
str = query.value(0).toString();
//qDebug() << str;
break; //just read the first text for testing.
}
QString tag = "([Dd]ubai|Abu\\s?Dhabi)"; //--> Dubai, dubai, abu dhabi, abudhabi
//QString pattern = QString("\\b(%1)\\b").arg(tag); //this can be used if you want to check for whole words only \b for word boundary.
QRegExp regEx(tag, Qt::CaseInsensitive);
int count = 0;
int pos = 0;
while( (pos = regEx.indexIn(str, pos) ) != -1)
{
QString foundTag = str.mid(pos, regEx.matchedLength() );
pos += regEx.matchedLength();
qDebug() << foundTag;
}
}
+46
View File
@@ -0,0 +1,46 @@
#ifndef SQLDialog_H
#define SQLDialog_H
#include <QtGui>
#include <QtSql>
namespace Ui
{
class SQLDialog;
}
class SQLDialog : public QDialog
{
Q_OBJECT
public:
SQLDialog(QWidget *parent = 0);
~SQLDialog();
void readSettings();
void connectToDB();
private:
Ui::SQLDialog *ui;
QString fileName;
QString fileContent;
QString m_masterDatabaseHost;
QString m_masterDatabaseName;
QString m_masterDatabaseUser;
QString m_masterDatabasePassword;
int m_masterDatabasePort;
QSqlDatabase m_masterDatabase;
private slots:
void on_pushButton_5_clicked();
void on_pushButton_4_clicked();
void on_pushButton_3_clicked();
void on_pushButton_2_clicked();
void on_pushButton_clicked();
};
#endif // SQLDialog_H
+85
View File
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SQLDialog</class>
<widget class="QDialog" name="SQLDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>280</width>
<height>101</height>
</rect>
</property>
<property name="windowTitle">
<string>SQLDialog</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>110</x>
<y>30</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>insert file</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>open file</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>190</x>
<y>30</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Get Dubai</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_4">
<property name="geometry">
<rect>
<x>30</x>
<y>60</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>دبي</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_5">
<property name="geometry">
<rect>
<x>110</x>
<y>60</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>RegEx</string>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>