use of db.JDBCTable in project common by zenlunatics.
the class Survey method writeCSV.
// ----------------------------------------------------------------------
public void writeCSV(Request request) throws IOException {
request.response.setContentType("text/csv");
try {
ArrayList<Integer> question_ids = new ArrayList<Integer>();
ResultSet questions = request.db.select("SELECT id,answer_type FROM survey_questions WHERE surveys_id=" + m_id + " ORDER BY _order_");
while (questions.next()) {
String type = questions.getString(2);
if (type.equals("Divider") || type.equals("HTML") || type.equals("Page Break"))
continue;
question_ids.add(new Integer(questions.getInt(1)));
}
questions.getStatement().close();
ResultSet answers = request.db.select("SELECT * FROM survey_answers" + m_id);
JDBCTable answer_table = request.db.getTable("survey_answers" + m_id);
HTMLWriter writer = request.writer;
while (answers.next()) {
boolean first = true;
for (int i : question_ids) {
if (first)
first = false;
else
writer.write(',');
String column_name = "a" + i;
if (answer_table.getColumn(column_name).isNumber())
writer.write(answers.getInt(column_name));
else {
String answer = answers.getString(column_name);
if (answer != null) {
writer.write('"');
writer.write(Util.escapeDoubleQuotes(answer));
writer.write('"');
}
}
}
writer.write('\n');
}
answers.getStatement().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of db.JDBCTable in project common by zenlunatics.
the class SiteMenu method init.
// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
JDBCTable jdbc_table = new JDBCTable().add(new JDBCColumn("name", Types.VARCHAR, 30)).add(new JDBCColumn("_order_", Types.INTEGER));
db.getTable("menu").dropExtraColumns(jdbc_table, db).createMissingColumns(jdbc_table, db);
jdbc_table = new JDBCTable().add(new JDBCColumn("people")).add(new JDBCColumn("name", Types.VARCHAR, 30)).add(new JDBCColumn("_order_", Types.INTEGER));
db.getTable("menu_items").dropExtraColumns(jdbc_table, db).createMissingColumns(jdbc_table, db);
m_menu = new DBObjects<MenuItem>(new Select("*").from("menu").orderBy("_order_"), MenuItem.class, m_site);
// so that the UpdateHook calls get called on reorder
m_site.addObjects(m_menu);
Pages pages = (Pages) m_site.getModule("Pages");
pages.add(new Page("Other", "Other"), db);
ViewDef view_def = m_site.getViewDef("pages", db);
view_def.addDeleteHook(this).addUpdateHook(this);
}
use of db.JDBCTable in project common by zenlunatics.
the class News method init.
// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
JDBCTable table_def = new JDBCTable().add(new JDBCColumn("provider", Types.VARCHAR)).add(new JDBCColumn("item_id", Types.INTEGER)).add(new JDBCColumn("_owner_", "people")).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP)).add(new JDBCColumn("last_update", Types.TIMESTAMP));
for (JDBCColumn column : m_additional_columns) table_def.add(column);
db.getTable("news", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
}
use of db.JDBCTable in project common by zenlunatics.
the class NewsFeed method init.
// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
JDBCTable table_def = new JDBCTable().add(new JDBCColumn("_owner_", "people")).add(new JDBCColumn("text", Types.VARCHAR)).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP));
addColumns(table_def);
db.getTable(m_table, true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
}
use of db.JDBCTable in project common by zenlunatics.
the class Discussions method init.
// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
JDBCTable table_def = new JDBCTable().add(new JDBCColumn("title", Types.VARCHAR, 60)).add(new JDBCColumn("text", Types.VARCHAR)).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP)).add(new JDBCColumn("_owner_", "people"));
addColumns(table_def);
db.getTable(m_table, true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
db.createManyTable(m_table, m_table + "_attachments", "filename VARCHAR");
}
Aggregations