2 * This file is part of NixNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 package cx.fbn.nevernote.sql;
\r
23 import java.util.ArrayList;
\r
24 import java.util.List;
\r
26 import com.trolltech.qt.core.QByteArray;
\r
28 import cx.fbn.nevernote.sql.driver.NSqlQuery;
\r
29 import cx.fbn.nevernote.utilities.ApplicationLogger;
\r
31 public class InkImagesTable {
\r
32 private final ApplicationLogger logger;
\r
33 DatabaseConnection db;
\r
36 public InkImagesTable(ApplicationLogger l,DatabaseConnection d) {
\r
41 public void createTable() {
\r
42 NSqlQuery query = new NSqlQuery(db.getConnection());
\r
43 // Create the NoteTag table
\r
44 logger.log(logger.HIGH, "Creating table InkImage...");
\r
45 if (!query.exec("Create table InkImages (guid varchar, " +
\r
46 "slice integer, primary key(guid, slice), image blob)"))
\r
47 logger.log(logger.HIGH, "Table InkImage creation FAILED!!!");
\r
50 public void dropTable() {
\r
51 NSqlQuery query = new NSqlQuery(db.getConnection());
\r
52 query.exec("drop table InkImages");
\r
55 public void expungeImage(String guid) {
\r
56 NSqlQuery query = new NSqlQuery(db.getConnection());
\r
57 if (!query.prepare("Delete from InkImages where guid=:guid ")) {
\r
58 logger.log(logger.EXTREME, "InkImage SQL prepare has failed.");
\r
59 logger.log(logger.MEDIUM, query.lastError());
\r
62 query.bindValue(":guid", guid);
\r
63 if (!query.exec()) {
\r
64 logger.log(logger.EXTREME, "InkImage SQL delete has failed.");
\r
65 logger.log(logger.MEDIUM, query.lastError());
\r
70 // Get a note tags by the note's Guid
\r
71 public List<QByteArray> getImage(String guid) {
\r
72 List<QByteArray> data = new ArrayList<QByteArray>();
\r
73 NSqlQuery query = new NSqlQuery(db.getConnection());
\r
74 if (!query.prepare("Select image from InkImages where guid = :guid order by slice")) {
\r
75 logger.log(logger.EXTREME, "InkImage SQL prepare has failed.");
\r
76 logger.log(logger.MEDIUM, query.lastError());
\r
79 query.bindValue(":guid", guid);
\r
80 if (!query.exec()) {
\r
81 logger.log(logger.EXTREME, "InkImage SQL exec has failed.");
\r
82 logger.log(logger.MEDIUM, query.lastError());
\r
85 while (query.next()) {
\r
86 data.add(new QByteArray(query.getBlob(0)));
\r
90 // Save an ink note image
\r
91 public void saveImage(String guid, int slice, QByteArray data) {
\r
92 logger.log(logger.HIGH, "Entering inkImageTable.saveImage");
\r
94 NSqlQuery query = new NSqlQuery(db.getConnection());
\r
95 check = query.prepare("Insert Into InkImages ("
\r
96 +"guid, slice, image) Values("
\r
97 +":guid, :slice, :data)");
\r
99 logger.log(logger.EXTREME, "InkImages SQL insert prepare has failed.");
\r
100 logger.log(logger.MEDIUM, query.lastError());
\r
103 query.bindValue(":guid", guid);
\r
104 query.bindValue(":slice", slice);
\r
105 query.bindBlob(":data", data.toByteArray());
\r
106 check = query.exec();
\r
108 logger.log(logger.MEDIUM, "*** InkImages Table insert failed.");
\r
109 logger.log(logger.MEDIUM, query.lastError());
\r
111 logger.log(logger.HIGH, "Leaving InkImages.saveImage");
\r