001: package net.sourceforge.squirrel_sql.plugins.sqlbookmark;
002:
003: public class DefaultBookmarksFactory {
004: private static final String[][] BOOKMARKS = {
005:
006: {
007: "crtab",
008: "create table ...",
009: "CREATE TABLE MyTable\n"
010: + "(\n"
011: + " MyID1 INTEGER not null,\n"
012: + " MyID2 INTEGER not null,\n"
013: + " MyTEXT VARCHAR(20),\n"
014: + " MyDate TIMESTAMP,\n"
015: + " CONSTRAINT MyTable_PK PRIMARY KEY (MyID1,MyID2)\n"
016: + ")" },
017:
018: { "addpk", "alter table add PK",
019: "ALTER TABLE MyTable ADD CONSTRAINT MyTable_PK PRIMARY KEY (MyID1,MyID2)" },
020:
021: { "addcol", "alter table add ...",
022: "ALTER TABLE MyTable ADD COLUMN MyCol Integer" },
023:
024: { "crix", "create index ...",
025: "CREATE [UNIQUE] INDEX MyTable_IX ON MyTable(MyCol1, MyCol2)" },
026:
027: {
028: "addconst",
029: "alter table ... add constraint ...",
030: "ALTER TABLE MyChild\n"
031: + "ADD CONSTRAINT FK_MyParent\n"
032: + "FOREIGN KEY (ParentPK1InChild, ParentPK2InChild)\n"
033: + "REFERENCES MyParent (ParentPK1, ParentPK2)" },
034:
035: {
036: "selwhere",
037: "select where",
038: "SELECT MyTable.MyTEXT, MyTable.*\n"
039: + "FROM MyTable\n" + "WHERE MyID1 = 1\n"
040: + " AND MyID2 = 3" },
041:
042: {
043: "join",
044: "select join",
045: "SELECT MyChild.*\n"
046: + "FROM MyParent\n"
047: + "[INNER | LEFT | RIGHT] JOIN MyChild ON MyParent.ParentPK1 = MyChild.ParentPK1InChild AND MyParent.ParentPK2 = MyChild.ParentPK2InChild\n"
048: + "WHERE MyParent.Name = 'Mom'" },
049:
050: {
051: "group",
052: "group by",
053: "SELECT SUM(price), Author\n" + "FROM Books\n"
054: + "GROUP BY Author" },
055:
056: {
057: "grouphaving",
058: "group by having",
059: "SELECT SUM(price), Author\n" + "FROM Books\n"
060: + "GROUP BY Author HAVING SUM(price) > 100" },
061:
062: {
063: "casesimple",
064: "simple form of case",
065: "SELECT\n" + "CASE MyText\n"
066: + " WHEN 'One' THEN 1 \n"
067: + " WHEN 'Two' THEN 2 \n"
068: + " ELSE -1 \n" + "END\n"
069: + "FROM MyTable" },
070:
071: {
072: "casesstandard",
073: "standard form of case",
074: "SELECT\n" + "CASE\n"
075: + " WHEN MyText = 'One' THEN 1 \n"
076: + " WHEN MyText = 'Two' THEN 2 \n"
077: + " ELSE -1 \n" + "END\n"
078: + "FROM MyTable" },
079:
080: {
081: "insertval",
082: "insert values",
083: "INSERT INTO MyTable\n"
084: + "(MyID1, MyID2, MyTEXT , MyDate) VALUES\n"
085: + "(1 , 100 , 'Hello', {ts '2005-06-13 23:25:00'})" },
086:
087: {
088: "insertsel",
089: "insert select",
090: "INSERT INTO MyTable (MyID1, MyID2, MyTEXT, MyDate) \n"
091: + "SELECT MyID1 + 100, MyID2 + 200 , MyTEXT || ' world', MyDate FROM MyTable" },
092:
093: {
094: "update",
095: "update",
096: "UPDATE MyTable set MyTEXT = 'Hello big world', MyDate = {ts '2005-06-13 23:36:00'}\n"
097: + "WHERE MyID1 = 1" },
098:
099: { "delete", "delete", "DELETE FROM MyTable WHERE MyID1 = 1" },
100:
101: { "paramexample", "bookmark with parameters",
102: "SELECT * FROM MyTable WHERE MyID1 = ${Value of MyID1}" } };
103:
104: static Bookmark[] getDefaultBookmarks() {
105: Bookmark[] ret = new Bookmark[BOOKMARKS.length];
106: for (int i = 0; i < BOOKMARKS.length; i++) {
107: ret[i] = new Bookmark(BOOKMARKS[i][0], BOOKMARKS[i][1],
108: BOOKMARKS[i][2]);
109: }
110:
111: return ret;
112: }
113:
114: }
|