dbName = name;
}
// Create the table
public void createTable(boolean addDefaulte) {
NSqlQuery query = new NSqlQuery(db.getConnection());
logger.log(logger.HIGH, "Creating table "+dbName+"...");
if (!query.exec("Create table "+dbName+" (guid varchar primary key, " +
"sequence integer, " +
"name varchar, "+
"defaultNotebook varchar, "+
"serviceCreated timestamp, " +
"serviceUpdated timestamp, "+
"published boolean, "+
"isDirty boolean, "+
"autoEncrypt boolean, "+
"local boolean, "+
"archived boolean)"))
logger.log(logger.HIGH, "Table "+dbName+" creation FAILED!!!");
Notebook newnote = new Notebook();
newnote.setDefaultNotebook(true);
newnote.setName("My Notebook");
newnote.setPublished(false);
newnote.setGuid("1");
// Setup an initial notebook
SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
query = new NSqlQuery(db.getConnection());
query.prepare("Insert Into "+dbName+" (guid, sequence, name, defaultNotebook, "
+"serviceCreated, serviceUpdated, published, "
+ "isDirty, autoEncrypt, "
+ "local, archived) Values("
+":guid, :sequence, :name, :defaultNotebook, "
+":serviceCreated, :serviceUpdated, :published, "
+":isDirty, :autoEncrypt, "
+":local, false)");
query.bindValue(":guid", newnote.getGuid());
query.bindValue(":sequence", newnote.getUpdateSequenceNum());
query.bindValue(":name", newnote.getName());
query.bindValue(":defaultNotebook", newnote.isDefaultNotebook());
StringBuilder serviceCreated = new StringBuilder(simple.format(newnote.getServiceCreated()));
StringBuilder serviceUpdated = new StringBuilder(simple.format(newnote.getServiceUpdated()));
if (serviceUpdated.toString() == null)
serviceUpdated = serviceCreated;
query.bindValue(":serviceCreated", serviceCreated.toString());
query.bindValue(":serviceUpdated", serviceCreated.toString());
query.bindValue(":published",newnote.isPublished());
query.bindValue(":isDirty", true);
query.bindValue(":autoEncrypt", false);
query.bindValue(":local", false);
boolean check = query.exec();
if (!check) {
logger.log(logger.MEDIUM, "Initial "+dbName+" Table insert failed.");
logger.log(logger.MEDIUM, query.lastError().toString());
}
}