OSDN Git Service

Added LaTex image insert & edit
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / NoteResourceTable.java
index 9c612e4..b3a0806 100644 (file)
@@ -82,6 +82,8 @@ public class NoteResourceTable  {
                query.bindValue(":guid", guid);\r
                if (!query.exec())\r
                        logger.log(logger.EXTREME, "Error resetting noteresource dirty field. " +query.lastError());\r
+               else\r
+                       query.exec("commit");\r
        }\r
        // Set if the resource should be indexed\r
        public void  setIndexNeeded(String guid, Boolean indexNeeded) {\r
@@ -91,6 +93,8 @@ public class NoteResourceTable  {
                query.bindValue(":guid", guid);\r
                if (!query.exec())\r
                        logger.log(logger.EXTREME, "Error setting noteresource indexneeded field: " +query.lastError());\r
+               else\r
+                       query.exec("commit");\r
        }\r
        // get any unindexed resource\r
        public List<String> getNextUnindexed(int limit) {\r
@@ -228,7 +232,8 @@ public class NoteResourceTable  {
                        if (!check) {\r
                                logger.log(logger.MEDIUM, "*** NoteResource Table insert failed.");             \r
                                logger.log(logger.MEDIUM, query.lastError());\r
-                       }\r
+                       } else\r
+                               query.exec("commit");\r
                        \r
                                                \r
                        logger.log(logger.HIGH, "Leaving DBRunner.saveNoteResources");\r
@@ -239,10 +244,13 @@ public class NoteResourceTable  {
                query.prepare("delete from NoteResources where guid=:guid");\r
                query.bindValue(":guid", guid);\r
                query.exec();\r
-\r
-               query.prepare("delete from InkImages where guid=:guid");\r
-               query.bindValue(":guid", guid);\r
-               query.exec();\r
+               query.exec("commit");\r
+               \r
+               NSqlQuery query2 = new NSqlQuery(db.getConnection());\r
+               query2.prepare("Delete from InkImages where guid=:guid");\r
+               query2.bindValue(":guid", guid);\r
+               query2.exec();\r
+               query2.exec("commit");\r
 \r
        }\r
 \r
@@ -348,7 +356,7 @@ public class NoteResourceTable  {
                                +"recognitionHash, recognitionSize, "\r
                                +"attributeLatitude, attributeLongitude, attributeAltitude, "\r
                                +"attributeCameraMake, attributeCameraModel, attributeClientWillIndex, "\r
-                               +"attributeRecoType, attributeFileName, attributeAttachment, recognitionBinary "\r
+                               +"attributeRecoType, attributeFileName, attributeAttachment, attributeSourceUrl "\r
                                +" from NoteResources where guid=:guid");\r
 \r
                \r
@@ -403,6 +411,7 @@ public class NoteResourceTable  {
                        a.setRecoType(stringValue(query.valueString(18)));                 // Recognition Type\r
                        a.setFileName(stringValue(query.valueString(19)));                  // File Name\r
                        a.setAttachment(booleanValue(query.valueString(20).toString(),false));\r
+                       a.setSourceURL(query.valueString(21));\r
                        r.setAttributes(a);\r
                \r
                        if (withBinary) {\r
@@ -521,12 +530,8 @@ public class NoteResourceTable  {
        // Save Note Resource\r
        public void updateNoteResource(Resource r, boolean isDirty) {\r
                logger.log(logger.HIGH, "Entering ListManager.updateNoteResource");\r
-               NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
-               query.prepare("delete from NoteResources where guid=:recGuid");\r
-               query.bindValue(":recGuid", r.getGuid());\r
-               query.exec();\r
+               expungeNoteResource(r.getGuid());\r
                saveNoteResource(r, isDirty);\r
-               query = null;\r
                logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteResource");\r
        }\r
        // Update note resource GUID\r
@@ -538,6 +543,7 @@ public class NoteResourceTable  {
                query.bindValue(":isDirty", isDirty);\r
                query.bindValue(":oldGuid", oldGuid);\r
                query.exec();\r
+               query.exec("commit");\r
                logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteResourceGuid");\r
        }\r
        // Update note resource GUID\r
@@ -548,6 +554,7 @@ public class NoteResourceTable  {
                query.bindValue(":isDirty", isDirty);\r
                query.bindValue(":guid", guid);\r
                query.exec();\r
+               query.exec("commit");\r
                logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteResourceGuid");\r
        }\r
        \r
@@ -555,6 +562,7 @@ public class NoteResourceTable  {
        public void reindexAll() {              \r
                NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
                query.exec("Update NoteResources set indexneeded=true");\r
+               query.exec("commit");\r
        }\r
        // Count attachments\r
        public int getResourceCount() {\r
@@ -625,4 +633,31 @@ public class NoteResourceTable  {
                        return unknown;\r
        }\r
 \r
+       // Update note source url. \r
+       public void updateNoteSourceUrl(String guid, String url, boolean isDirty) {\r
+               logger.log(logger.HIGH, "Entering RNoteResourceTable.updateNoteSourceUrl()");\r
+               NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
+               query.prepare("update NoteResources set attributesourceurl=:url, isDirty=:isDirty where guid=:guid");\r
+               query.bindValue(":guid", guid);\r
+               query.bindValue(":isDirty", isDirty);\r
+               query.bindValue(":url", url);\r
+               query.exec();\r
+               query.exec("commit");\r
+               logger.log(logger.HIGH, "Leaving RNoteResourceTable.updateNoteSourceUrl()");\r
+       }\r
+       \r
+       // Get note source\r
+       public String getNoteSourceUrl(String guid) {\r
+               logger.log(logger.HIGH, "Entering RNoteResourceTable.getNoteSourceUrl()");\r
+               NSqlQuery query = new NSqlQuery(db.getResourceConnection());\r
+               query.prepare("Select attributesourceurl from noteresources where guid=:guid");\r
+               query.bindValue(":guid", guid);\r
+               query.exec();\r
+               if (query.next()) {\r
+                       logger.log(logger.HIGH, "Leaving RNoteResourceTable.getNoteSourceUrl()");\r
+                       return query.valueString(0);\r
+               }\r
+               logger.log(logger.HIGH, "Leaving RNoteResourceTable.getNoteSourceUrl() - no value found");\r
+               return null;\r
+       }\r
 }\r