figure out the the autoincrement value for the given table
497830
def _get_auto_increment_info(self, table):
        """"""
        query = ''
        seq_table = ''
        seq_column = ''
        seq_name = ''
        find_query = "\n".join([
            "SELECT",
            "  t.relname as related_table,",
            "  a.attname as related_column,",
            "  s.relname as sequence_name",
            "FROM pg_class s",
            "JOIN pg_depend d ON d.objid = s.oid",
            "JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid",
            "JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)",
            "JOIN pg_namespace n ON n.oid = s.relnamespace",
            "WHERE",
            "  s.relkind = 'S'",
            "AND",
            "  n.nspname = 'public'",
            "AND",
            "  t.relname = '{}'".format(table)
        ])

        pipe = self._run_queries([find_query], popen_kwargs={'stdout': subprocess.PIPE})
        stdout, stderr = pipe.communicate()
        if stdout:
            try:
                m = re.findall('^\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*$', stdout, flags=re.MULTILINE)
                seq_table, seq_column, seq_name = m[1]
                # http://www.postgresql.org/docs/9.2/static/functions-sequence.html
                # http://www.postgresql.org/docs/9.2/static/functions-conditional.html
                query = "\n".join([
                    "SELECT",
                    "  setval('{}',".format(seq_name.strip()),
                    "  coalesce(max({}), 1),".format(seq_column.strip()),
                    "  max({}) IS NOT null)".format(seq_column.strip()),
                    "FROM \"{}\"".format(seq_table.strip())
                ])

            except IndexError:
                query = ''

        return query, seq_table, seq_column, seq_name
880734
private void computeIJTable(InfoTree it, int subtreePreorder,
			int subtreeRevPreorder, int subtreeSize, int aStrategy, int treeSize) {

		int change;

		int[] post2pre = it.info[POST2_PRE];
		int[] rpost2post = it.info[RPOST2_POST];

		if (aStrategy == LEFT) {
			for (int x = 0; x < subtreeSize; x++) {
				ij[0][x] = x + subtreePreorder;
			}
			for (int x = 1; x < subtreeSize; x++) {
				change = post2pre[(treeSize - 1 - (x - 1 + subtreeRevPreorder))];
				for (int z = 0; z < subtreeSize; z++) {
					if (ij[x - 1][z] >= change) {
						ij[x][z] = ij[x - 1][z] + 1;
					} else {
						ij[x][z] = ij[x - 1][z];
					}
				}
			}
		} else { // if (aStrategy == RIGHT) {
			for (int x = 0; x < subtreeSize; x++) {
				ij[0][x] = x + subtreeRevPreorder;
			}
			for (int x = 1; x < subtreeSize; x++) {
				change = treeSize
						- 1
						- rpost2post[(treeSize - 1 - (x - 1 + subtreePreorder))];
				for (int z = 0; z < subtreeSize; z++) {
					if (ij[x - 1][z] >= change) {
						ij[x][z] = ij[x - 1][z] + 1;
					} else {
						ij[x][z] = ij[x - 1][z];
					}
				}
			}
		}
	}
1119386
private function getAutoIncrementFields(Table $table) : array
    {
        $moduleName = Inflector::camelize($table->getTable());
        $mc = new ModuleConfig(ConfigType::FIELDS(), $moduleName);
        $config = json_encode($mc->parse());
        $config = false === $config ? [] : json_decode($config, true);

        if (empty($config)) {
            return [];
        }

        $result = [];
        foreach (array_keys($table->getFieldsDefinitions()) as $field) {
            $autoIncrement = empty($config[$field]['auto-increment']) ? false : (bool)$config[$field]['auto-increment'];
            if (!$autoIncrement) {
                continue;
            }
            $result[$field] = [];

            $min = empty($config[$field]['min']) ? null : $config[$field]['min'];
            if (!is_int($min) && !is_float($min)) {
                continue;
            }

            $result[$field] = [
                'min' => $min
            ];
        }

        return $result;
    }
755201
def integer(self, column, auto_increment=False, unsigned=False):
        
        return self._add_column(
            "integer", column, auto_increment=auto_increment, unsigned=unsigned
        )
1249397
String getTableRightsSQL(Table table) {

        StringBuffer sb = new StringBuffer();

        if (isFull) {
            return Tokens.T_ALL;
        }

        if (isFullSelect) {
            sb.append(Tokens.T_SELECT);
            sb.append(',');
        } else if (selectColumnSet != null) {
            sb.append(Tokens.T_SELECT);
            getColumnList(table, selectColumnSet, sb);
            sb.append(',');
        }

        if (isFullInsert) {
            sb.append(Tokens.T_INSERT);
            sb.append(',');
        } else if (insertColumnSet != null) {
            sb.append(Tokens.T_INSERT);
            getColumnList(table, insertColumnSet, sb);
            sb.append(',');
        }

        if (isFullUpdate) {
            sb.append(Tokens.T_UPDATE);
            sb.append(',');
        } else if (updateColumnSet != null) {
            sb.append(Tokens.T_UPDATE);
            getColumnList(table, updateColumnSet, sb);
            sb.append(',');
        }

        if (isFullDelete) {
            sb.append(Tokens.T_DELETE);
            sb.append(',');
        }

        if (isFullReferences) {
            sb.append(Tokens.T_REFERENCES);
            sb.append(',');
        } else if (referencesColumnSet != null) {
            sb.append(Tokens.T_REFERENCES);
            sb.append(',');
        }

        if (isFullTrigger) {
            sb.append(Tokens.T_TRIGGER);
            sb.append(',');
        } else if (triggerColumnSet != null) {
            sb.append(Tokens.T_TRIGGER);
            sb.append(',');
        }

        return sb.toString().substring(0, sb.length() - 1);
    }
810519
def increment(self, conn, seqName, transaction = False, incCount=1):
        
	try:
	    seqTable = "%sS" %seqName
	    tlock = "lock tables %s write" %seqTable
	    self.dbi.processData(tlock, [], conn, transaction)
	    sql = "select ID from %s" % seqTable
	    result = self.dbi.processData(sql, [], conn, transaction)
	    resultlist = self.formatDict(result)
	    newSeq = resultlist[0]['id']+incCount
	    sql = "UPDATE %s SET ID=:seq_count" % seqTable
	    seqparms={"seq_count" : newSeq}
	    self.dbi.processData(sql, seqparms, conn, transaction)
	    tunlock = "unlock tables"
	    self.dbi.processData(tunlock, [], conn, transaction)
	    return newSeq
	except:
	    #FIXME
	    tunlock = "unlock tables"
	    self.dbi.processData(tunlock, [], conn, transaction)
	    raise
993702
def count_entries(self, table=None):
        """"""
        if table is None: table = self.main_table
        self.own_cursor.execute('SELECT COUNT(1) FROM "%s";' % table)
        return int(self.own_cursor.fetchone()[0])
1314132
def stringpatterncounter(table, field):
    

    trans = maketrans(
        'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
        'AAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaa9999999999'
    )
    counter = Counter()
    for v in values(table, field):
        p = str(v).translate(trans)
        counter[p] += 1
    return counter
698505
def values(self):
        
        table_id = 0
        get = self.get___method
        for cell_id in range(self.width):
            val = get(self, table_id, cell_id)
            if val:
                yield val
958978
private String arith(){

        if(params.length != 3){
            throw new IllegalArgumentException("Wrong number of Parameters for arithmetic expression");
        }

        double res = 0;
        try{
            String operator = params[2];

            double firstValue = Double.parseDouble(record.getValueByFieldName(params[0]));

            double secondValue = Double.parseDouble(record.getValueByFieldName(params[1]));


            if("+".equals(operator)){
                res = firstValue + secondValue;
            }else if("-".equals(operator)){
                res = firstValue - secondValue;
            }else if("*".equals(operator)){
                res = firstValue * secondValue;
            }else if("/".equals(operator)){
                res = firstValue / secondValue;
            }else if("%".equals(operator)){
                res = (firstValue / secondValue) * 100;
            }

            NumberFormat decimalFormat = NumberFormat.getFormat(".##");
            res = Double.parseDouble(decimalFormat.format(res));
        }catch(Exception e){
            System.err.println("Error calculating table arithmetic function");
        }
        return Double.toString(res);

    }
822588
def get_number(self, num, table=None):
        """"""
        if table is None: table = self.main_table
        self.own_cursor.execute('SELECT * from "%s" LIMIT 1 OFFSET %i;' % (self.main_table, num))
        return self.own_cursor.fetchone()
541639
def count(self, table):
        
        if self._operator is None and self._operands is None:
            return self._get_table_len(table)

        return np.count_nonzero(self.mask(table))
408163
public int getAndIncrement (K key, int defaultValue, int increment) {
		int hashCode = System.identityHashCode(key);
		int index = hashCode & mask;
		if (key != keyTable[index]) {
			index = hash2(hashCode);
			if (key != keyTable[index]) {
				index = hash3(hashCode);
				if (key != keyTable[index]) {
					if (bigTable) {
						index = hash4(hashCode);
						if (key != keyTable[index]) return getAndIncrementStash(key, defaultValue, increment);
					} else {
						return getAndIncrementStash(key, defaultValue, increment);
					}
				}
			}
		}
		int value = valueTable[index];
		valueTable[index] = value + increment;
		return value;
	}
217190
private static int getRolledValue(int value, int amount, int min, int max) {
        assert value >= min && value <= max;
        int range = max - min + 1;
        amount %= range;
        int n = value + amount;
        if (n > max) {
            n -= range;
        } else if (n < min) {
            n += range;
        }
        assert n >= min && n <= max;
        return n;
    }
1352706
def _restore_auto_increment(self, table):
        """"""
        query, seq_table, seq_column, seq_name = self._get_auto_increment_info(table)
        if query:
            queries = [query, "select nextval('{}')".format(seq_name)]
            return self._run_queries(queries)
282824
public static function GetAutoIncrementColumns (array $options, $table_name, $forced_obtain = false) {
		$options += $options + static::GetDefaultOptions();
		return DBI::GetAutoIncrementColumns($options, static::GetName(), $forced_obtain);
	}
366928
static public int obtainNextIncrementInteger(Connection connection, ColumnData autoIncrementIntegerColumn) throws Exception {
		try {
			String sqlQuery = "SELECT nextval(?);";

			// Create SQL command
			PreparedStatement pstmt = null;
			{
				pstmt = connection.prepareStatement(sqlQuery);
				
				// Populate prepared statement
				pstmt.setString(1, autoIncrementIntegerColumn.getAutoIncrementSequence());
			}

			if( pstmt.execute() ) {
				ResultSet rs = pstmt.getResultSet();
				if( rs.next() ) {
					int nextValue = rs.getInt(1);
					
					return nextValue;
				} else {
					throw new Exception("Empty result returned by SQL: "+sqlQuery);
				}
				
			} else {
				throw new Exception("No result returned by SQL: "+sqlQuery);
			}
		} catch( Exception e ) {
			throw new Exception("Error while attempting to get a auto increment integer value for: "+
					autoIncrementIntegerColumn.getColumnName()+
					" ("+autoIncrementIntegerColumn.getAutoIncrementSequence()+")",e);
		}
	}