- try {
- PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id,subject, md, csr_name, crt_name,memid, profile FROM `certs` WHERE serial=?");
- ps.setString(1, serial);
- ResultSet rs = ps.executeQuery();
- if ( !rs.next()) {
- throw new IllegalArgumentException("Invalid mid " + serial);
- }
- this.id = rs.getInt(1);
- dn = rs.getString(2);
- md = rs.getString(3);
- csrName = rs.getString(4);
- crtName = rs.getString(5);
- ownerId = rs.getInt(6);
- profile = CertificateProfile.getById(rs.getInt(7));
- this.serial = serial;
-
- PreparedStatement ps2 = DatabaseConnection.getInstance().prepare("SELECT contents, type FROM `subjectAlternativeNames` WHERE certId=?");
- ps2.setInt(1, id);
- ResultSet rs2 = ps2.executeQuery();
- sans = new LinkedList<>();
- while (rs2.next()) {
- sans.add(new SubjectAlternateName(SANType.valueOf(rs2.getString("type").toUpperCase()), rs2.getString("contents")));
- }
- rs2.close();
-
- rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
+ //
+ String concat = "group_concat(concat('/', `name`, '=', REPLACE(REPLACE(value, '\\\\', '\\\\\\\\'), '/', '\\\\/')))";
+ GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT certs.id, " + concat + " as subject, md, csr_name, crt_name,memid, profile FROM `certs` LEFT JOIN certAvas ON certAvas.certid=certs.id WHERE serial=? GROUP BY certs.id");
+ ps.setString(1, serial);
+ GigiResultSet rs = ps.executeQuery();
+ if ( !rs.next()) {
+ throw new IllegalArgumentException("Invalid mid " + serial);
+ }
+ this.id = rs.getInt(1);
+ dnString = rs.getString(2);
+ md = rs.getString(3);
+ csrName = rs.getString(4);
+ crtName = rs.getString(5);
+ owner = User.getById(rs.getInt(6));
+ profile = CertificateProfile.getById(rs.getInt(7));
+ this.serial = serial;
+
+ GigiPreparedStatement ps2 = DatabaseConnection.getInstance().prepare("SELECT contents, type FROM `subjectAlternativeNames` WHERE certId=?");
+ ps2.setInt(1, id);
+ GigiResultSet rs2 = ps2.executeQuery();
+ sans = new LinkedList<>();
+ while (rs2.next()) {
+ sans.add(new SubjectAlternateName(SANType.valueOf(rs2.getString("type").toUpperCase()), rs2.getString("contents")));