Examples of ISQLConnection


Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

            return TI_ERROR_MESSAGE;

         String whereClause = getWhereClause(values, colDefs, col, newValue);

         final ISession session = _session;
         final ISQLConnection conn = session.getSQLConnection();

         int count = -1// start with illegal number of rows matching query

         try
         {
            final Statement stmt = conn.createStatement();
            try
            {
               final ResultSet rs = stmt.executeQuery("select count(*) from "
                              + ti.getQualifiedName() + whereClause);
               rs.next();
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

      // partial data, such as "matches <data>*", but that may not be
      // standard accross all Databases and thus may be risky.
      String whereClause = getWhereClause(values, colDefs, -1, null);

      final ISession session = _session;
      final ISQLConnection conn = session.getSQLConnection();

      Object wholeDatum = null;

      try
      {
         final Statement stmt = conn.createStatement();
         final String queryString =
            "SELECT " + colDefs[col].getColumnName() +" FROM "+ti.getQualifiedName() +
            whereClause;

         try
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

      if (s_log.isDebugEnabled()) {
          s_log.debug("updateTableComponent: whereClause = "+whereClause);
      }
     
      final ISession session = _session;
      final ISQLConnection conn = session.getSQLConnection();

      int count = -1;

      final String sql = constructUpdateSql(
            ti.getQualifiedName(), colDefs[col].getColumnName(), whereClause);
     
      if (s_log.isDebugEnabled()) {
          s_log.debug("updateTableComponent: executing SQL - "+sql);
      }
      PreparedStatement pstmt = null;
      try
      {
         pstmt = conn.prepareStatement(sql);

         // have the DataType object fill in the appropriate kind of value
         // into the first (and only) variable position in the prepared stmt
         CellComponentFactory.setPreparedStatementValue(
                colDefs[col], pstmt, newValue, 1);
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

      if (ti == null)
         return TI_ERROR_MESSAGE;

      // get the SQL session
      final ISession session = _session;
      final ISQLConnection conn = session.getSQLConnection();

      // string used as error indicator and description of problems seen
      // when checking for 0 or mulitple matches in DB
      String rowCountErrorMessage = "";

      // for each row in table, count how many rows match where clause
      // if not exactly one, generate message describing situation
      for (int i = 0; i < rowData.length; i++) {
         // get WHERE clause for the selected row
         // the -1 says to just use the contents of the values without
         // any substitutions
         String whereClause = getWhereClause(rowData[i], colDefs, -1, null);

         // count how many rows this WHERE matches
         try {
            // do the delete and add the number of rows deleted to the count
            final Statement stmt = conn.createStatement();
            try
            {
               ResultSet rs = stmt.executeQuery("SELECT count(*) FROM " +
                  ti.getQualifiedName()+whereClause);

               rs.next();
               if (rs.getInt(1) != 1) {
                  if (rs.getInt(1) == 0) {
                      // i18n[DataSetUpdateableTableModelImpl.error.rownotmatch=\n   Row {0}  did not match any row in DB]
                     rowCountErrorMessage +=
                         s_stringMgr.getString(
                                 "DataSetUpdateableTableModelImpl.error.rownotmatch",
                                 Integer.valueOf(i+1));
                  } else {
                      //i18n[DataSetUpdateableTableModelImpl.error.rowmatched=\n   Row {0} matched {1} rows in DB]
                      rowCountErrorMessage +=
                          s_stringMgr.getString(
                                  "DataSetUpdateableTableModelImpl.error.rowmatched",
                                  new Object[] { Integer.valueOf(i+1), Integer.valueOf(rs.getInt(1)) });
                  }
               }
            }
            finally
            {
               stmt.close();
            }
         }
         catch (Exception e) {
            // some kind of problem - tell user
             // i18n[DataSetUpdateableTableModelImpl.error.preparingdelete=While preparing for delete, saw exception:\n{0}]
             return
                 s_stringMgr.getString(
                         "DataSetUpdateableTableModelImpl.error.preparingdelete",
                         e);
         }
      }

      // if the rows do not match 1-for-1 to DB, ask user if they
      // really want to do delete
      if (rowCountErrorMessage.length() > 0) {
          // i18n[DataSetUpdateableTableModelImpl.error.tabledbmismatch=There may be a mismatch between the table and the DB:\n{0}\nDo you wish to proceed with the deletes anyway?]
          String msg =
              s_stringMgr.getString("DataSetUpdateableTableModelImpl.error.tabledbmismatch",
                                    rowCountErrorMessage);
        
         int option =
             JOptionPane.showConfirmDialog(null, msg, "Warning",
                                           JOptionPane.YES_NO_OPTION,
                                           JOptionPane.WARNING_MESSAGE);
        
         if ( option != JOptionPane.YES_OPTION) {
             // i18n[DataSetUpdateableTableModelImpl.info.deletecancelled=Delete canceled at user request.]
            return s_stringMgr.getString("DataSetUpdateableTableModelImpl.info.deletecancelled");
         }
      }

      // for each row in table, do delete and add to number of rows deleted from DB
      for (int i = 0; i < rowData.length; i++) {
         // get WHERE clause for the selected row
         // the -1 says to just use the contents of the values without
         // any substitutions
         String whereClause = getWhereClause(rowData[i], colDefs, -1, null);

         // try to delete
         try {
            // do the delete and add the number of rows deleted to the count
            final Statement stmt = conn.createStatement();
            try
            {
               stmt.executeUpdate("DELETE FROM " +
                  ti.getQualifiedName() + whereClause);
            }
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

      {
         return defaultValues;
      }

      final ISession session = _session;
      final ISQLConnection conn = session.getSQLConnection();

      try
      {
         SQLDatabaseMetaData md = conn.getSQLMetaData();
         TableColumnInfo[] infos = md.getColumnInfo(ti);
        
         // read the DB MetaData info and fill in the value, if any
         // Note that the ResultSet info and the colDefs should be
         // in the same order, but we cannot guarantee that.
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

      if (ti == null) {
         return TI_ERROR_MESSAGE;
      }
     
      final ISession session = _session;
      final ISQLConnection conn = session.getSQLConnection();
     
      int count = -1;
     
      try
      {
         // start the string for use in the prepared statment
         StringBuilder buf = new StringBuilder("INSERT INTO ");
         buf.append(ti.getQualifiedName());

         // Add the list of column names we will be inserting into - be sure
         // to skip the rowId column and any auto increment columns.
         buf.append(" ( ");
         for (int i=0; i<colDefs.length; i++) {
             if (i == _rowIDcol) {
                 continue;
             }
             if (colDefs[i].isAutoIncrement()) {
                 if (s_log.isInfoEnabled()) {
                     s_log.info("insertRow: skipping auto-increment column "+
                                colDefs[i].getColumnName());
                 }
                 continue;
             }
             buf.append(colDefs[i].getColumnName());
             buf.append(",");
         }
         buf.setCharAt(buf.length()-1, ')');
         buf.append(" VALUES (");
        
         // add a variable position for each of the columns
         for (int i=0; i<colDefs.length; i++) {
            if (i != _rowIDcol && !colDefs[i].isAutoIncrement() )
               
               buf.append(" ?,");
         }

         // replace the last "," with ")"
         buf.setCharAt(buf.length()-1, ')');

         String pstmtSQL = buf.toString();
         if (s_log.isInfoEnabled()) {
             s_log.info("insertRow: pstmt sql = "+pstmtSQL);
         }
         final PreparedStatement pstmt = conn.prepareStatement(pstmtSQL);

         try
         {
            // We need to keep track of the bind var index separately, since
            // the number of column defs may not be the number of bind vars
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

  public List<ObjectTreeNode> createChildren(ISession session, ObjectTreeNode parentNode)
    throws SQLException
  {
    final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
    final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo();
    final ISQLConnection conn = session.getSQLConnection();
    final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData();
    final String catalogName = parentDbinfo.getCatalogName();
    final String schemaName = parentDbinfo.getSchemaName();
    final ObjFilterMatcher filterMatcher = new ObjFilterMatcher(session.getProperties());

    final String sequenceParentQuerySql = extractor.getSequenceParentQuery();
    if (s_log.isDebugEnabled()) {
      s_log.debug("createChildren: running sequence parent query for sequence children: "
        + sequenceParentQuerySql);
    }

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try
    {
      pstmt = conn.prepareStatement(sequenceParentQuerySql);   
      extractor.bindParameters(pstmt, parentDbinfo, filterMatcher);

      rs = pstmt.executeQuery();
      while (rs.next())
      {
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

  {
    final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
    final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo();
    final IDatabaseObjectInfo tableInfo = ((IndexParentInfo) parentDbinfo).getTableInfo();

    final ISQLConnection conn = session.getSQLConnection();
    final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try
    {
      String query = extractor.getTableIndexQuery();
      if (s_log.isDebugEnabled())
      {
        s_log.debug("Running query for index extraction: " + query);
      }
      pstmt = conn.prepareStatement(query);
      extractor.bindParamters(pstmt, tableInfo);
      rs = pstmt.executeQuery();
      while (rs.next())
      {
        String indexName = rs.getString(1);
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

   }

   private class SetAutoCommitTask implements Runnable {
       
        public void run() {
            final ISQLConnection conn = _session.getSQLConnection();
            final SessionProperties props = _session.getProperties();
            if (conn != null)
            {
                boolean auto = true;
                try
                {
                    auto = conn.getAutoCommit();
                }
                catch (SQLException ex)
                {
                    s_log.error("Error with transaction control", ex);
                    _session.showErrorMessage(ex);
                }
                try
                {
                    conn.setAutoCommit(props.getAutoCommit());
                }
                catch (SQLException ex)
                {
                    props.setAutoCommit(auto);
                    _session.showErrorMessage(ex);
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

    final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
    Statement stmt = null;
    try
    {
      final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo();
      final ISQLConnection conn = session.getSQLConnection();
      final String catalogName = parentDbinfo.getCatalogName();
      final String schemaName = parentDbinfo.getSchemaName();
      final String tableType = parentDbinfo.getSimpleName();

      String[] types = tableType != null ? new String[] { tableType } : null;
      session.getSchemaInfo().waitTillTablesLoaded();
      final ITableInfo[] tables =
        session.getSchemaInfo().getITableInfos(catalogName, schemaName,
          new ObjFilterMatcher(session.getProperties()), types);

      if (session.getProperties().getShowRowCount())
      {
        stmt = conn.createStatement();
      }

      for (int i = 0; i < tables.length; ++i)
      {
        ObjectTreeNode child = new ObjectTreeNode(session, tables[i]);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.