Skip to content

Commit 46fcfb4

Browse files
author
Jim Hamill
committed
Bug fixes
1 parent f3c1088 commit 46fcfb4

9 files changed

+231
-264
lines changed

ExplorerWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void ExplorerWidget::addTable()
103103
void ExplorerWidget::removeTable()
104104
{
105105
// Display messagebox for confirmation
106-
if (QMessageBox::Yes == QMessageBox::question(this, "Drop Table", "Are you sure you want to drop this table?")) {
106+
if (ui->tableListWidget->currentItem() && QMessageBox::Yes == QMessageBox::question(this, "Drop Table", "Are you sure you want to drop this table?")) {
107107

108108
// Get table name
109109
QString table = ui->tableListWidget->currentItem()->text();

Extension/MySQLExtension.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ QMap<QString, int> MySQLExtension::getDataTypes()
234234
types["text"] = NO_PROPERTIES;
235235
types["varchar"] = HAS_LENGTH | HAS_NULLABLE | HAS_DEFAULT;
236236
types["int"] = HAS_LENGTH + HAS_NULLABLE + HAS_DEFAULT;
237+
types["int unsigned"] = HAS_LENGTH + HAS_NULLABLE + HAS_DEFAULT;
237238
types["date"] = NO_PROPERTIES;;
238239
types["datetime"] = NO_PROPERTIES;;
239240
types["timestamp"] = NO_PROPERTIES;;

QueryWidget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ QueryWidget::QueryWidget(QWidget *parent) :
1717
// Attach SQL Highlighter
1818
m_highlighter = new SQLHighlighter(ui->queryEdit->document());
1919

20-
// Connect history's click with fill function
20+
// Connect history and saved queries
2121
connect(ui->queryHistoryWidget, SIGNAL(querySelected(QString)), this, SLOT(setQuery(QString)));
22+
connect(ui->savedQueryWidget, SIGNAL(querySelected(QString)), this, SLOT(setQuery(QString)));
2223
connect(ui->savedQueryWidget, SIGNAL(addButtonClicked()), this, SLOT(saveQuery()));
2324
}
2425

QuteSQL.pro

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
1111
TARGET = qutesql
1212
TEMPLATE = app
1313

14+
LIBS += -lz
15+
1416
VERSION = 0.1
1517
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
1618

@@ -34,7 +36,8 @@ SOURCES += main.cpp\
3436
ColumnDialog.cpp \
3537
Database.cpp \
3638
Utilities/SQLSplitter.cpp \
37-
Tools/SQLSplitterDialog.cpp
39+
Tools/SQLSplitterDialog.cpp \
40+
Utilities/QCompressor.cpp
3841

3942
HEADERS += MainWindow.h \
4043
DatabaseConnectionWidget.h \
@@ -55,7 +58,8 @@ HEADERS += MainWindow.h \
5558
ColumnDialog.h \
5659
Database.h \
5760
Utilities/SQLSplitter.h \
58-
Tools/SQLSplitterDialog.h
61+
Tools/SQLSplitterDialog.h \
62+
Utilities/QCompressor.h
5963

6064
FORMS += MainWindow.ui \
6165
DatabaseConnectionWidget.ui \

QuteSQL.pro.user

Lines changed: 0 additions & 260 deletions
This file was deleted.

SavedQueryWidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ void SavedQueryWidget::saveQueries()
7474
}
7575
settings.endArray();
7676
}
77+
78+
void SavedQueryWidget::on_listWidget_itemActivated(QListWidgetItem *item)
79+
{
80+
emit querySelected(item->text());
81+
}

SavedQueryWidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <QWidget>
55
#include <QSqlDatabase>
6+
#include <QListWidgetItem>
67

78
namespace Ui {
89
class SavedQueryWidget;
@@ -30,10 +31,12 @@ class SavedQueryWidget : public QWidget
3031

3132
signals:
3233
void addButtonClicked();
34+
void querySelected(const QString &);
3335

3436
private slots:
3537
void on_addButton_clicked();
3638
void on_removeButton_clicked();
39+
void on_listWidget_itemActivated(QListWidgetItem *item);
3740
};
3841

3942
#endif // SAVEDQUERYWIDGET_H

Utilities/QCompressor.cpp

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
#include "QCompressor.h"
2+
3+
/**
4+
* @brief Compresses the given buffer using the standard GZIP algorithm
5+
* @param input The buffer to be compressed
6+
* @param output The result of the compression
7+
* @param level The compression level to be used (@c 0 = no compression, @c 9 = max, @c -1 = default)
8+
* @return @c true if the compression was successful, @c false otherwise
9+
*/
10+
bool QCompressor::gzipCompress(QByteArray input, QByteArray &output, int level)
11+
{
12+
// Prepare output
13+
output.clear();
14+
15+
// Is there something to do?
16+
if(input.length())
17+
{
18+
// Declare vars
19+
int flush = 0;
20+
21+
// Prepare deflater status
22+
z_stream strm;
23+
strm.zalloc = Z_NULL;
24+
strm.zfree = Z_NULL;
25+
strm.opaque = Z_NULL;
26+
strm.avail_in = 0;
27+
strm.next_in = Z_NULL;
28+
29+
// Initialize deflater
30+
int ret = deflateInit2(&strm, qMax(-1, qMin(9, level)), Z_DEFLATED, GZIP_WINDOWS_BIT, 8, Z_DEFAULT_STRATEGY);
31+
32+
if (ret != Z_OK)
33+
return(false);
34+
35+
// Prepare output
36+
output.clear();
37+
38+
// Extract pointer to input data
39+
char *input_data = input.data();
40+
int input_data_left = input.length();
41+
42+
// Compress data until available
43+
do {
44+
// Determine current chunk size
45+
int chunk_size = qMin(GZIP_CHUNK_SIZE, input_data_left);
46+
47+
// Set deflater references
48+
strm.next_in = (unsigned char*)input_data;
49+
strm.avail_in = chunk_size;
50+
51+
// Update interval variables
52+
input_data += chunk_size;
53+
input_data_left -= chunk_size;
54+
55+
// Determine if it is the last chunk
56+
flush = (input_data_left <= 0 ? Z_FINISH : Z_NO_FLUSH);
57+
58+
// Deflate chunk and cumulate output
59+
do {
60+
61+
// Declare vars
62+
char out[GZIP_CHUNK_SIZE];
63+
64+
// Set deflater references
65+
strm.next_out = (unsigned char*)out;
66+
strm.avail_out = GZIP_CHUNK_SIZE;
67+
68+
// Try to deflate chunk
69+
ret = deflate(&strm, flush);
70+
71+
// Check errors
72+
if(ret == Z_STREAM_ERROR)
73+
{
74+
// Clean-up
75+
deflateEnd(&strm);
76+
77+
// Return
78+
return(false);
79+
}
80+
81+
// Determine compressed size
82+
int have = (GZIP_CHUNK_SIZE - strm.avail_out);
83+
84+
// Cumulate result
85+
if(have > 0)
86+
output.append((char*)out, have);
87+
88+
} while (strm.avail_out == 0);
89+
90+
} while (flush != Z_FINISH);
91+
92+
// Clean-up
93+
(void)deflateEnd(&strm);
94+
95+
// Return
96+
return(ret == Z_STREAM_END);
97+
}
98+
else
99+
return(true);
100+
}
101+
102+
/**
103+
* @brief Decompresses the given buffer using the standard GZIP algorithm
104+
* @param input The buffer to be decompressed
105+
* @param output The result of the decompression
106+
* @return @c true if the decompression was successfull, @c false otherwise
107+
*/
108+
bool QCompressor::gzipDecompress(QByteArray input, QByteArray &output)
109+
{
110+
// Prepare output
111+
output.clear();
112+
113+
// Is there something to do?
114+
if(input.length() > 0)
115+
{
116+
// Prepare inflater status
117+
z_stream strm;
118+
strm.zalloc = Z_NULL;
119+
strm.zfree = Z_NULL;
120+
strm.opaque = Z_NULL;
121+
strm.avail_in = 0;
122+
strm.next_in = Z_NULL;
123+
124+
// Initialize inflater
125+
int ret = inflateInit2(&strm, GZIP_WINDOWS_BIT);
126+
127+
if (ret != Z_OK)
128+
return(false);
129+
130+
// Extract pointer to input data
131+
char *input_data = input.data();
132+
int input_data_left = input.length();
133+
134+
// Decompress data until available
135+
do {
136+
// Determine current chunk size
137+
int chunk_size = qMin(GZIP_CHUNK_SIZE, input_data_left);
138+
139+
// Check for termination
140+
if(chunk_size <= 0)
141+
break;
142+
143+
// Set inflater references
144+
strm.next_in = (unsigned char*)input_data;
145+
strm.avail_in = chunk_size;
146+
147+
// Update interval variables
148+
input_data += chunk_size;
149+
input_data_left -= chunk_size;
150+
151+
// Inflate chunk and cumulate output
152+
do {
153+
154+
// Declare vars
155+
char out[GZIP_CHUNK_SIZE];
156+
157+
// Set inflater references
158+
strm.next_out = (unsigned char*)out;
159+
strm.avail_out = GZIP_CHUNK_SIZE;
160+
161+
// Try to inflate chunk
162+
ret = inflate(&strm, Z_NO_FLUSH);
163+
164+
switch (ret) {
165+
case Z_NEED_DICT:
166+
ret = Z_DATA_ERROR;
167+
case Z_DATA_ERROR:
168+
case Z_MEM_ERROR:
169+
case Z_STREAM_ERROR:
170+
// Clean-up
171+
inflateEnd(&strm);
172+
173+
// Return
174+
return(false);
175+
}
176+
177+
// Determine decompressed size
178+
int have = (GZIP_CHUNK_SIZE - strm.avail_out);
179+
180+
// Cumulate result
181+
if(have > 0)
182+
output.append((char*)out, have);
183+
184+
} while (strm.avail_out == 0);
185+
186+
} while (ret != Z_STREAM_END);
187+
188+
// Clean-up
189+
inflateEnd(&strm);
190+
191+
// Return
192+
return (ret == Z_STREAM_END);
193+
}
194+
else
195+
return(true);
196+
}

Utilities/QCompressor.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef QCOMPRESSOR_H
2+
#define QCOMPRESSOR_H
3+
4+
#include <zlib.h>
5+
#include <QByteArray>
6+
7+
#define GZIP_WINDOWS_BIT 15 + 16
8+
#define GZIP_CHUNK_SIZE 32 * 1024
9+
10+
class QCompressor
11+
{
12+
public:
13+
static bool gzipCompress(QByteArray input, QByteArray &output, int level = -1);
14+
static bool gzipDecompress(QByteArray input, QByteArray &output);
15+
};
16+
17+
#endif // QCOMPRESSOR_H

0 commit comments

Comments
 (0)