~sgdg/stado/stado25

« back to all changes in this revision

Viewing changes to src/org/postgresql/stado/metadata/MetaUtils.java

  • Committer: Jim Mlodgenski
  • Date: 2011-08-30 22:39:37 UTC
  • mfrom: (1.1.3 stado)
  • Revision ID: jim@cirrusql.com-20110830223937-25q231a31x0e08b4
Merge from Spatial branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Copyright (C) 2008 EnterpriseDB Corporation.
3
3
 * Copyright (C) 2011 Stado Global Development Group.
4
4
 *
5
 
 * This program is free software; you can redistribute it and/or modify it
6
 
 * under the terms of the GNU General Public License version 2 as published by
7
 
 * the Free Software Foundation.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
10
 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12
 
 * more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License along
15
 
 * with this program; if not, see http://www.gnu.org/licenses or write to the
16
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
 
 * 02110-1301 USA.
 
5
 * This file is part of Stado.
 
6
 *
 
7
 * Stado is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * Stado is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with Stado.  If not, see <http://www.gnu.org/licenses/>.
18
19
 *
19
20
 * You can find Stado at http://www.stado.us
20
21
 *
48
49
        int[] colIDs = new int[columnDefinitions.size()];
49
50
        SqlCreateTableColumn aSqlCreateTableColumn;
50
51
        String sqlStatement;
51
 
        String xsyscolumnsBaseStr = "INSERT INTO xsyscolumns" + "(colid, "
 
52
        String xsyscolumnsBaseStr = "INSERT INTO xsyscolumns" + "("
52
53
                + "tableid, " + "colseq," + "colname, " + "coltype, "
53
54
                + "collength, " + "colscale, " + "colprecision,"
54
55
                + "isnullable," + "isserial," + "DEFAULTEXPR, " + "CHECKEXPR, "
55
56
                + "nativecoldef)" + " values ";
56
 
        sqlStatement = "SELECT max(colid) FROM xsyscolumns";
57
 
        ResultSet rs = MetaData.getMetaData().executeQuery(sqlStatement);
58
 
        int colid;
59
 
        try {
60
 
            rs.next();
61
 
            colid = rs.getInt(1) + 1;
62
 
        } finally {
63
 
            rs.close();
64
 
        }
65
57
 
66
58
        for (int i = 0, seq = begColSeq + 1; i < columnDefinitions.size(); i++, seq++) {
67
59
            aSqlCreateTableColumn = columnDefinitions.get(i);
68
 
            colIDs[i] = colid++;
69
60
            sqlStatement = xsyscolumnsBaseStr
70
61
                    + "("
71
 
                    + colIDs[i]
72
 
                    + ","
73
62
                    + tableid
74
63
                    + ","
75
64
                    + seq
108
97
 
109
98
            sqlStatement += "'"
110
99
                    + aSqlCreateTableColumn.rebuildString().replaceAll("'",
111
 
                            "''") + "')";
112
 
 
113
 
            MetaData.getMetaData().executeUpdate(sqlStatement);
 
100
                            "''") + "') RETURNING colid";
 
101
 
 
102
            ResultSet keys = MetaData.getMetaData().executeUpdateReturning(sqlStatement);
 
103
            if (keys.next()) {
 
104
                colIDs[i] = keys.getInt(1);
 
105
            } else {
 
106
                throw new Exception("Error creating table");
 
107
            }
 
108
 
114
109
        }
115
110
        return colIDs;
116
111
    }