import cx.fbn.nevernote.evernote.NoteMetadata;\r
import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
import cx.fbn.nevernote.utilities.ApplicationLogger;\r
+import cx.fbn.nevernote.utilities.Pair;\r
\r
public class NoteTable {\r
private final ApplicationLogger logger;\r
query.bindValue(":attributeSource", n.getAttributes().getSource());\r
query.bindValue(":attributeSourceUrl", n.getAttributes().getSourceURL());\r
query.bindValue(":attributeSourceApplication", n.getAttributes().getSourceApplication());\r
+ } else {\r
+ created = new StringBuilder(simple.format(n.getCreated())); \r
+ query.bindValue(":attributeSubjectDate", created.toString());\r
+ query.bindValue(":attributeLatitude", 0.0);\r
+ query.bindValue(":attributeLongitude", 0.0);\r
+ query.bindValue(":attributeAltitude", 0.0);\r
+ query.bindValue(":attributeAuthor", "");\r
+ query.bindValue(":attributeSource", "");\r
+ query.bindValue(":attributeSourceUrl", "");\r
+ query.bindValue(":attributeSourceApplication", "");\r
}\r
query.bindValue(":indexNeeded", true);\r
query.bindValue(":isExpunged", false);\r
+"created, updated, deleted, active, notebookGuid, "\r
+"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
+"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication, "\r
+ +"attributeContentClass, "\r
+"content, contentHash, contentLength"\r
+" from Note where guid=:guid and isExpunged=false")) {\r
logger.log(logger.EXTREME, "Note SQL select prepare with content has failed.");\r
+"guid, updateSequenceNumber, title, "\r
+"created, updated, deleted, active, notebookGuid, "\r
+"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
- +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication "\r
+ +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication, "\r
+ +"attributeContentClass"\r
+" from Note where guid=:guid and isExpunged=false")) {\r
logger.log(logger.EXTREME, "Note SQL select prepare without content has failed.");\r
logger.log(logger.MEDIUM, getQueryWithoutContent.lastError());\r
+"guid, updateSequenceNumber, title, "\r
+"created, updated, deleted, active, notebookGuid, "\r
+"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
- +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication "\r
+ +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication, "\r
+ +"attributeContentClass "\r
+" from Note where isExpunged = false")) {\r
logger.log(logger.EXTREME, "Note SQL select prepare without content has failed.");\r
logger.log(logger.MEDIUM, getQueryWithoutContent.lastError());\r
}\r
Note n = mapNoteFromQuery(query, loadContent, loadResources, loadRecognition, loadBinary, loadTags);\r
n.setContent(fixCarriageReturn(n.getContent()));\r
+ n.getAttributes().setContentClassIsSet(false);\r
return n;\r
}\r
// Get a note by Guid\r
na.setSource(query.valueString(13));\r
na.setSourceURL(query.valueString(14));\r
na.setSourceApplication(query.valueString(15));\r
+ na.setContentClass(query.valueString(16));\r
\r
if (loadTags) {\r
- n.setTagGuids(noteTagsTable.getNoteTags(n.getGuid()));\r
+ List<String> tagGuids = noteTagsTable.getNoteTags(n.getGuid());\r
List<String> tagNames = new ArrayList<String>();\r
TagTable tagTable = db.getTagTable();\r
- for (int i=0; i<n.getTagGuids().size(); i++) {\r
- String currentGuid = n.getTagGuids().get(i);\r
+ for (int i=0; i<tagGuids.size(); i++) {\r
+ String currentGuid = tagGuids.get(i);\r
Tag tag = tagTable.getTag(currentGuid);\r
- tagNames.add(tag.getName());\r
+ if (tag.getName() != null)\r
+ tagNames.add(tag.getName());\r
+ else\r
+ tagNames.add("");\r
}\r
+\r
n.setTagNames(tagNames);\r
+ n.setTagGuids(tagGuids); \r
}\r
\r
if (loadContent) {\r
QTextCodec codec = QTextCodec.codecForLocale();\r
codec = QTextCodec.codecForName("UTF-8");\r
- String unicode = codec.fromUnicode(query.valueString(16)).toString();\r
+ String unicode = codec.fromUnicode(query.valueString(17)).toString();\r
\r
// This is a hack. Basically I need to convert HTML Entities to "normal" text, but if I\r
// convert the < character to < it will mess up the XML parsing. So, to get around this\r
// I'm done I convert it back.\r
StringBuffer buffer = new StringBuffer(unicode);\r
if (Global.enableHTMLEntitiesFix && unicode.indexOf("&#") > 0) {\r
- unicode = query.valueString(16);\r
+ unicode = query.valueString(17);\r
//System.out.println(unicode);\r
//unicode = unicode.replace("<", "&_lt;");\r
//unicode = codec.fromUnicode(StringEscapeUtils.unescapeHtml(unicode)).toString();\r
n.setContent(unicode);\r
// n.setContent(query.valueString(16).toString());\r
\r
- String contentHash = query.valueString(17);\r
+ String contentHash = query.valueString(18);\r
if (contentHash != null)\r
n.setContentHash(contentHash.getBytes());\r
- n.setContentLength(new Integer(query.valueString(18)));\r
+ n.setContentLength(new Integer(query.valueString(19)));\r
}\r
if (loadResources)\r
n.setResources(noteResourceTable.getNoteResources(n.getGuid(), loadBinary));\r
}\r
public void restoreNote(String guid) {\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
- query.prepare("Update Note set deleted='1969-12-31 19.00.00', active=true, isDirty=true where guid=:guid");\r
+ query.prepare("Update Note set deleted=:reset, active=true, isDirty=true where guid=:guid");\r
// query.prepare("Update Note set deleted=0, active=true, isDirty=true where guid=:guid");\r
query.bindValue(":guid", guid);\r
+ query.bindValue(":reset", "1969-12-31 19:00:00");\r
if (!query.exec()) {\r
logger.log(logger.MEDIUM, "Note restore failed.");\r
logger.log(logger.MEDIUM, query.lastError());\r
return values;\r
}\r
\r
+ // Find a note based upon its title.\r
+ public List<Pair<String,String>> findNotesByTitle(String text) {\r
+ List<Pair<String,String>> results = new ArrayList<Pair<String,String>>();\r
+ boolean check; \r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ check = query.prepare("Select guid,title from Note where lower(title) like :title");\r
+ if (!check) \r
+ logger.log(logger.EXTREME, "Note SQL prepare for search by title has failed: " +query.lastError().toString());\r
+ \r
+ query.bindValue(":title", "%"+text.toLowerCase()+"%");\r
+ query.exec();\r
+ // Get a list of the notes\r
+ while (query.next()) {\r
+ Pair<String,String> p = new Pair<String,String>();\r
+ p.setFirst(query.valueString(0));\r
+ p.setSecond(query.valueString(1)); \r
+ results.add(p); \r
+ } \r
+ return results;\r
+ }\r
+\r
\r
\r
//********************************************************************************\r