Search in sources :

Example 6 with JDBCTable

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);
    }
}
Also used : HTMLWriter(web.HTMLWriter) SQLException(java.sql.SQLException) JDBCTable(db.JDBCTable) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Example 7 with JDBCTable

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);
}
Also used : Pages(app.Pages) JDBCTable(db.JDBCTable) Select(db.Select) JDBCColumn(db.JDBCColumn) Page(app.Page) ViewDef(db.ViewDef)

Example 8 with JDBCTable

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);
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 9 with JDBCTable

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);
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 10 with JDBCTable

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");
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Aggregations

JDBCTable (db.JDBCTable)17 JDBCColumn (db.JDBCColumn)14 Select (db.Select)4 Page (app.Page)3 Request (app.Request)3 SQLException (java.sql.SQLException)3 Options (db.Options)2 ViewDef (db.ViewDef)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 HTMLWriter (web.HTMLWriter)2 Module (app.Module)1 Pages (app.Pages)1 DBConnection (db.DBConnection)1 OneToMany (db.OneToMany)1 Reorderable (db.Reorderable)1 Schema (db.Schema)1 RoleAccessPolicy (db.access.RoleAccessPolicy)1 LookupColumn (db.column.LookupColumn)1 BufferedReader (java.io.BufferedReader)1