Insert the maximum of 1 and the number of selected rows
178078
def OnInsertRows(self, event):
        """"""

        bbox = self.grid.selection.get_bbox()

        if bbox is None or bbox[1][0] is None:
            # Insert rows at cursor
            ins_point = self.grid.actions.cursor[0] - 1
            no_rows = 1
        else:
            # Insert at lower edge of bounding box
            ins_point = bbox[0][0] - 1
            no_rows = self._get_no_rowscols(bbox)[0]

        with undo.group(_("Insert rows")):
            self.grid.actions.insert_rows(ins_point, no_rows)

        self.grid.GetTable().ResetView()

        # Update the default sized cell sizes
        self.grid.actions.zoom()

        event.Skip()
388510
def Insert(self, key, value, row_index):
        
        if row_index < 0:
            row_index += len(self)

        if not 0 <= row_index < len(self):
            raise IndexError('Index "%s" is out of bounds.' % row_index)

        new_row = Row()
        for idx in self.header:
            if self.index(idx) == row_index:
                new_row[key] = value
            new_row[idx] = self[idx]
        self._keys = new_row.header
        self._values = new_row.values
        del new_row
        self._BuildIndex()
862528
def last_column
      max = 0
      @data.each do |row|
        max = row.length if max < row.length
      end
      max - 1
    end
1220386
def insert_at(position = 1)
      list_class.transaction do
        ids = lock_list!
        position = [[1, position].max, ids.size].min

        if persisted?
          current_position = ids.index(id) + 1

          sql = <<-SQL
            #{quoted_position_column} = CASE
            WHEN #{quoted_position_column} = #{current_position} THEN #{position}
            WHEN #{quoted_position_column} > #{current_position}
            AND #{quoted_position_column} <= #{position} THEN #{quoted_position_column} - 1
            WHEN #{quoted_position_column} < #{current_position}
            AND #{quoted_position_column} >= #{position} THEN #{quoted_position_column} + 1
            ELSE #{quoted_position_column}
            END
          SQL

          list_scope.update_all(sql)
          update_position(position)
        else
          save!

          sql = <<-SQL
            #{quoted_position_column} = CASE
            WHEN #{quoted_position_column} >= #{position} THEN #{quoted_position_column} + 1
            ELSE #{quoted_position_column}
            END
          SQL

          list_scope.update_all(sql)
          update_position(position)
        end
      end
    end
1350866
function add_row() {

    $this->__row++;
    $this->_num_rows++;

    // Find the next available column
    $i = 0;
    while ( isset($this->_cells[$this->__row][$i]) )
      $i++;

    $this->__col = $i;

  }
715110
def insertRow(self, position):
        
        if position == -1:
            position = self.nrows()
        defaultparam = { 'start': 0,
                         'step': 0,
                         'stop': 0,
                         'parameter': '',
                         'selection' : [],
                        }
        self._parameters.insert(position, defaultparam)
1353063
def insert(self, fields, values):
        '''
        
        '''
        if fields:
            _fields = ' (%s) ' % ','.join(fields)
        else:
            _fields = ''
        _values = ','.join('?' * len(values))
        query = '''
        INSERT INTO %s %s VALUES (%s)
        ''' % (self._name, _fields, _values)
        self._cursor.execute(query, tuple(values))
        self._connection.commit()
        return self._cursor.lastrowid
281927
function applyLimit(&$sql, $offset, $limit) {

		$max = $offset + $limit;

		// nesting all queries, in case there's already a WHERE clause
		$sql = <<<EOF
SELECT A.*, rownum AS PROPEL\$ROWNUM
FROM (
  $sql
) A
WHERE rownum <= $max
EOF;

		if ($offset > 0) {
			$sql = <<<EOF
SELECT B.*
FROM (
  $sql
) B
WHERE B.PROPEL\$ROWNUM > $offset
EOF;
		}
	}
744018
private String getRowLineBuf(int colCount, List<Integer> colMaxLenList, String[][] data) {
		
		S.Buffer rowBuilder = S.buffer();
		int colWidth;
		
		for (int i = 0 ; i < colCount ; i ++) {
			
			colWidth = colMaxLenList.get(i) + 3;
			
			for (int j = 0; j < colWidth ; j ++) {
				if (j==0) {
					rowBuilder.append("+");
				} else if ((i+1 == colCount && j+1 == colWidth)) {//for last column close the border
					rowBuilder.append("-+");
				} else {
					rowBuilder.append("-");
				}
			}
		}
		
		return rowBuilder.append("\n").toString();
	}
1027410
def insert(self, events):
        """"""
        if not len(events):
            return
        keys = sorted(events[0].keys())
        ss = ','.join(['%s' for _ in keys])
        query = 'INSERT INTO %s (%s) VALUES ' % (self.table, ','.join(keys))
        data = []
        for event in events:
            query += '(%s),' % ss
            data += [event[k] for k in keys]
        query = query[:-1] + ';'
        LOG.info("%s (data: %s)", query, data)
        conn = self.conn.conn
        cursor = conn.cursor()
        cursor.execute(query, data)
        conn.commit()
666302
def _batch_insert(self, inserts, intervals, **kwargs):
    '''
    
    '''
    for timestamp,names in inserts.iteritems():
      for name,values in names.iteritems():
        for value in values:
          self._insert( name, value, timestamp, intervals, **kwargs )
461496
function () {
      var select, data, r, maxR, c;

      if (selection.isMultiple()) {
        select = priv.selectionBorder.corners;
      }
      else {
        select = priv.currentBorder.corners;
      }

      autofill.fillBorder.disappear();

      data = datamap.getAll();
      rows : for (r = select.BR.row + 1; r < self.rowCount; r++) {
        for (c = select.TL.col; c <= select.BR.col; c++) {
          if (data[r][c]) {
            break rows;
          }
        }
        if (!!data[r][select.TL.col - 1] || !!data[r][select.BR.col + 1]) {
          maxR = r;
        }
      }
      if (maxR) {
        autofill.showBorder(self.view.getCellAtCoords({row: maxR, col: select.BR.col}));
        autofill.apply();
      }
    }
120636
def select_row(statement, build_arg = nil)
    rows = select(statement, build_arg)
    raise UnexpectedQueryResult, "selected #{rows.size} rows; expected 1" unless rows.size == 1
    rows[0]
  end
513898
public static List<List<Object>> runInsertSelect(
      DBConnectionFactory connectionFactory, String sql,
    List<Object> sqlParams, boolean isWrite, int numRetries,
    int retryMaxInternalSec, boolean insert, boolean getGeneratedKeys)
        throws IOException {
    int waitMS = 3000; // wait for at least 3s before next retry.
    for (int i = 0; i < numRetries; ++i) {
      Connection conn = null;
      ResultSet generatedKeys = null;
      PreparedStatement pstmt = null;
      String url = null;
      try {
        try {
          url = connectionFactory.getUrl(isWrite);
        } catch (IOException ioe) {
          LOG.warn("Cannot get DB URL, fall back to the default one", ioe);
          url = defaultUrls.get(isWrite);
          if (url == null) {
            throw ioe;
          }
        }
        LOG.info("Attepting connection with URL " + url);
        conn = connectionFactory.getConnection(url);
        defaultUrls.put(isWrite, url);
        pstmt = getPreparedStatement(conn, sql, sqlParams,
            getGeneratedKeys);
        if (insert) {
          int recordsUpdated = pstmt.executeUpdate();
          LOG.info("rows inserted: " + recordsUpdated + " sql: " + sql);
          List<List<Object>> results = null;
          if (getGeneratedKeys) {
            generatedKeys = pstmt.getGeneratedKeys();
            results = getResults(generatedKeys);
          }
          Thread.sleep(connectionFactory.getDBOpsSleepTime() +
              rand.nextInt(1000));
          return results;
        }
        else {
          generatedKeys = pstmt.executeQuery();
          List<List<Object>> results = getResults(generatedKeys);
          pstmt.clearBatch();
          LOG.info("rows selected: " + results.size() + " sql: " + sql);
          Thread.sleep(connectionFactory.getDBOpsSleepTime() +
              rand.nextInt(1000));
          return results;
        }
      } catch (Exception e) {
        // We should catch a better exception than Exception, but since
        // DBConnectionUrlFactory.getUrl() defines throws Exception, it's hard
        // for us to figure out the complete set it can throw. We follow
        // DBConnectionUrlFactory.getUrl()'s definition to catch Exception.
        // It shouldn't be a big problem as after numRetries, we anyway exit.
        LOG.info("Exception " + e + ". Will retry " + (numRetries - i)
            + " times.");
        // Introducing a random factor to the wait time before another retry.
        // The wait time is dependent on # of failures and a random factor.
        // At the first time of getting a SQLException, the wait time
        // is a random number between [0,300] msec. If the first retry
        // still fails, we will wait 300 msec grace period before the 2nd retry.
        // Also at the second retry, the waiting window is expanded to 600 msec
        // alleviating the request rate from the server. Similarly the 3rd retry
        // will wait 600 msec grace period before retry and the waiting window
        // is
        // expanded to 1200 msec.

        waitMS += waitMS;
        if (waitMS > retryMaxInternalSec * 1000) {
          waitMS = retryMaxInternalSec * 1000;
        }
        double waitTime = waitMS + waitMS * rand.nextDouble();
        if (i + 1 == numRetries) {
          LOG.error("Still got Exception after " + numRetries + "  retries.",
              e);
          throw new IOException(e);
        }
        try {
          Thread.sleep((long) waitTime);
        } catch (InterruptedException ie) {
          throw new IOException(ie);
        }
      } finally {
        DBUtils.close(generatedKeys, new PreparedStatement[]{pstmt}, conn);
      }
    }
    return null;
  }
716766
function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $secs=0)
	{
		$nrows = (integer) $nrows;
		$offset = (integer) $offset;
		$str = 'SELECT ';
		if ($nrows >= 0) $str .= "FIRST $nrows ";
		$str .=($offset>=0) ? "SKIP $offset " : '';

		$sql = preg_replace('/^[ \t]*select/i',$str,$sql);
		if ($secs)
			$rs = $this->CacheExecute($secs,$sql,$inputarr);
		else
			$rs = $this->Execute($sql,$inputarr);

		return $rs;
	}
627707
def insert(self, row):
        
        data = self._convert_value(row)
        self._service.InsertRow(data, self._ss.id, self.id)
1166904
def OnInsertCols(self, event):
        """"""

        bbox = self.grid.selection.get_bbox()

        if bbox is None or bbox[1][1] is None:
            # Insert rows at cursor
            ins_point = self.grid.actions.cursor[1] - 1
            no_cols = 1
        else:
            # Insert at right edge of bounding box
            ins_point = bbox[0][1] - 1
            no_cols = self._get_no_rowscols(bbox)[1]

        with undo.group(_("Insert columns")):
            self.grid.actions.insert_cols(ins_point, no_cols)

        self.grid.GetTable().ResetView()

        # Update the default sized cell sizes
        self.grid.actions.zoom()

        event.Skip()