#include <iostream>
#include <cstring>
using namespace std;
unsigned int BinDec(char* bin)
{
unsigned int rez(0), n;
for(n = 0; n < strlen(bin); ++n) {
rez <<= 1;
rez += bin[n] - '0';
}
return rez;
}
void DecBin(unsigned int number, char* result)
{
int n;
for(n = 0; n < 32; ++n) {
result[n] = (number & 0x80000000) ? '1' : '0';
number <<= 1;
}
result[32] = 0;
}
int main()
{
char bin[] = "10110110100111100010010110111010";
unsigned int nn = BinDec(bin);
cout << bin << " = " << nn << endl;
char *binn = new char[33];
DecBin(nn, binn);
cout << nn << " = " << binn << endl;
if (strcmp(bin, binn) == 0)
cout << "OK" << endl;
else
cout << "False" << endl;
delete [] binn;
return 0;
}
SELECT * FROM nametable WHERE IsNull(col1,'') like '%"+ui->text_pole_1->text()+"%' ;
SELECT * FROM nametable WHERE IfNull(col1,'') like '%"+ui->text_pole_1->text()+"%' ;
SELECT * FROM nametable WHERE coalesce(col1,'') like '%"+ui->text_pole_1->text()+"%' ;
SELECT * FROM nametable WHERE nvl(col1,'') like '%"+ui->text_pole_1->text()+"%' ;
SET NAMES utf8
SELECT
ships.sudovlad,
s1.gruz_pass as summa,
EXTRACT(YEAR FROM s1.data_vih_p_ot) as years,
((s2.gruz_pass - s1.gruz_pass) / s1.gruz_pass * 100) AS percent,
s2.gruz_pass as summa2,
EXTRACT(YEAR FROM s2.data_vih_p_ot) AS years2
FROM ships
LEFT JOIN ships as s1
ON ships.sudovlad = s1.sudovlad AND EXTRACT(YEAR FROM s1.data_vih_p_ot)=2017 AND s1.sudovlad IN ('Русфлот, ООО', 'АрктикТранс ОИЛ, ООО','pere')
LEFT JOIN ships as s2
ON ships.sudovlad = s2.sudovlad AND EXTRACT(YEAR FROM s2.data_vih_p_ot)=2018 AND s2.sudovlad IN ('Русфлот, ООО', 'АрктикТранс ОИЛ, ООО','pere')
GROUP BY sudovlad
SELECT
reservtable.sudovlad,
reservtable.summa,
reservtable.years,
((reservtable2.summa2 - reservtable.summa) / reservtable.summa * 100) AS percent,
reservtable2.summa2,
reservtable2.years2
FROM(
SELECT sudovlad,gruz_pass as summa,EXTRACT(YEAR FROM data_vih_p_ot) AS years
FROM ships
WHERE EXTRACT(YEAR FROM data_vih_p_ot) = 2017 AND sudovlad IN ('Русфлот, ООО', 'АрктикТранс ОИЛ, ООО')
GROUP BY sudovlad) reservtable,
(SELECT sudovlad,gruz_pass as summa2,EXTRACT(YEAR FROM data_vih_p_ot) AS years2
FROM ships
WHERE EXTRACT(YEAR FROM data_vih_p_ot) = 2018 AND sudovlad IN ('Русфлот, ООО', 'АрктикТранс ОИЛ, ООО')
GROUP BY sudovlad) reservtable2
GROUP BY sudovlad
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "memdb");
db.setDatabaseName(":memory:");
if (!db.open())
{
qDebug() << db.lastError().text();
// std::exit(1);
}
QSqlQuery q("", db);
q.exec("create table Universities (id integer primary key, Location varchar, Population integer)");
q.exec("insert into Universities values (0, 'MSK', 12000000)");
q.exec("insert into Universities values (1, 'NSK', 1600000)");
q.exec("insert into Universities values (2, 'SPB', 6000000)");
q.exec("insert into Universities values (3, 'PRM', 1000000)");
int sz = ui->tableWidget->rowCount();
QString queryString = "SELECT * FROM Universities WHERE Location IN (";
for(int i = 0; i < sz; ++i)
{
queryString += "?,";
}
queryString.back() = ')';
QSqlQuery query(queryString, db);
for(int i = 0; i < sz; ++i)
{
query.bindValue(i, ui->tableWidget->item(i, 0)->text());
}
if (!query.exec())
{
qDebug() << query.lastError().text();
// std::exit(1);
}
while(query.next())
{
qDebug() << query.value(0).toInt() << " "
<< query.value(1).toString() << " "
<< query.value(2).toInt() << "\n";
}
QSqlQuery query;
query.prepare("SELECT * FROM Universities WHERE Location IN (?)");
int sz = ui->tableWidget->rowCount();
QVariantList values;
for(int i = 0; i < sz; ++i)
{
values << ui->tableWidget->item(i, 0)->text();
}
query.addBindValue(values);
if (!query.execBatch())
{
qDebug() << query.lastError();
}