Convert any limit usage
Doesn't work with the mssql variety
340914
protected function limit(&$query)
    {
        switch ($this->mode) {

            case "mysql":
            case "postgres":
            case "redshift":
            case "sqlite":
                $query = preg_replace("/\bFETCH\s+FIRST\s+([0-9]+)\s+ROW(S?)\s+ONLY\b/i", "\nLIMIT $1\n", $query);
                break;

            case "odbc":
                $query = preg_replace("/\bLIMIT\s+([0-9]+)\b/i", "\nFETCH FIRST $1 ROWS ONLY\n", $query);
                break;
        }
    }
966153
public static function limit($value, $limit = 100, $end = '...')
    {
        if (mb_strwidth($value, 'UTF-8') <= $limit) {
            return $value;
        }

        return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
    }
772948
def find_all(self, table, limit=10):
        '''
        
        '''
        sql = "select * from {} limit 0,{}".format(table, limit)
        res = self.query(sql)
        return res
483938
function limitationList( $useCache = true, $ignoreLimitIdentifier = false )
    {
        if ( !isset( $this->Limitations ) || !$useCache )
        {

            $limitations = eZPersistentObject::fetchObjectList( eZPolicyLimitation::definition(),
                                                                 null, array( 'policy_id' => $this->attribute( 'id') ), null, null,
                                                                 true );

            eZDebugSetting::writeDebug( 'kernel-policy-limitation', $limitations, "before policy limitations " . $this->ID );
            eZDebugSetting::writeDebug( 'kernel-policy-limitation', $this, "policy itself before before limitations check"  );

            if ( $ignoreLimitIdentifier === false  && isset( $this->LimitIdentifier ) && $this->LimitIdentifier )
            {
                $limitIdentifier =  $this->attribute( 'limit_identifier' );
                $limitValue = $this->attribute( 'limit_value' );
                $limitationTouched = false;
                $checkEmptyLimitation = true;
                foreach ( $limitations as $limitation )
                {
                    if ( $limitation->attribute( 'identifier' ) == $limitIdentifier )
                    {
                        if ( $limitIdentifier == 'Subtree' )
                        {
                            $limitationTouched = true;

                            $values = $limitation->attribute( 'values' );

                            foreach ( $values as $limitationValue )
                            {
                                $value = $limitationValue->attribute( 'value' );
                                if ( strpos( $value, $limitValue ) === 0 )
                                {
                                    $checkEmptyLimitation = false;
                                    eZDebugSetting::writeDebug( 'kernel-policy-limitation', $value,
                                                                "Limitationvalue has been left in the limitation [limitValue=$limitValue]" );
                                }
                                else if ( strpos( $limitValue, $value ) === 0 )
                                {
                                    $checkEmptyLimitation = false;
                                    $limitationValue->setAttribute( 'value', $limitValue );
                                    eZDebugSetting::writeDebug(  'kernel-policy-limitation',
                                                                 $value,
                                                                 "Limitationvalue has been exchanged to the value from cond assignment [limitValue=$limitValue]" );
                                }
                                else
                                {
                                    eZDebugSetting::writeDebug(  'kernel-policy-limitation',  $value,
                                                                 "Limitationvalue has been removed from limitation [limitValue=$limitValue]" );
                                    //exlude limitation value from limitation..
                                    unset( $limitationValue );
                                }
                            }
                            if ( $checkEmptyLimitation )
                            {
                                eZDebugSetting::writeDebug( 'kernel-policy-limitation', $this, 'The policy has been disabled' );
                                $this->Disabled = true;
                                $this->Limitations = array();
                                return $this->Limitations;
                            }
                        }
                    }
                }

                if ( !$limitationTouched )
                {
                    $policyLimitation = new eZPolicyLimitation( array ( 'id' => -1,
                                                                        'policy_id' => $this->attribute( 'id' ),
                                                                        'identifier' => $this->attribute( 'limit_identifier' ) ) );
                    $policyLimitation->setAttribute( 'limit_value', $this->attribute( 'limit_value' ) );

                    $limitations[] = $policyLimitation;
                }
            }
            eZDebugSetting::writeDebug( 'kernel-policy-limitation', $limitations, "policy limitations " . $this->ID );

            $this->Limitations = $limitations;
        }
        return $this->Limitations;
    }
907974
protected function applyLimit($sql){
		list($limit, $offset) = $this->stmt->getLimit();

		if((int) $limit > 0){
			$sql .= "\nLIMIT " . (int) $limit;
			if((int) $offset > 0)
				$sql .= ' OFFSET ' . (int) $offset;
		}
		return $sql;
	}
1249411
@Nonnull
  public Query limit(int limit) {
    QueryOptions newOptions = new QueryOptions(options);
    newOptions.limit = limit;
    return new Query(firestore, path, newOptions);
  }
858038
public Object convertJavaFieldToSqlArgValue(Object fieldVal) throws SQLException {
		/*
		 * Limitation here. Some people may want to override the null with their own value in the converter but we
		 * currently don't allow that. Specifying a default value I guess is a better mechanism.
		 */
		if (fieldVal == null) {
			return null;
		} else {
			return fieldConverter.javaToSqlArg(this, fieldVal);
		}
	}
1084785
public List<Message> getFilteredList( EMessageType messageType, Long fromTsMillis, Long toTsMillis, long limit )
            throws Exception {
        String tableName = TABLE_MESSAGES;
        String sql = "select " + getQueryFieldsString() + " from " + tableName;

        List<String> wheresList = new ArrayList<>();
        if (messageType != null && messageType != EMessageType.ALL) {
            String where = type_NAME + "=" + messageType.getCode();
            wheresList.add(where);
        }
        if (fromTsMillis != null) {
            String where = TimeStamp_NAME + ">" + fromTsMillis;
            wheresList.add(where);
        }
        if (toTsMillis != null) {
            String where = TimeStamp_NAME + "<" + toTsMillis;
            wheresList.add(where);
        }

        if (wheresList.size() > 0) {
            sql += " WHERE ";
            for( int i = 0; i < wheresList.size(); i++ ) {
                if (i > 0) {
                    sql += " AND ";
                }
                sql += wheresList.get(i);
            }
        }

        sql += " order by " + ID_NAME + " desc";
        if (limit > 0) {
            sql += " limit " + limit;
        }

        String _sql = sql;
        List<Message> messages = new ArrayList<Message>();
        logDb.execOnConnection(connection -> {
            try (IHMStatement stmt = connection.createStatement(); IHMResultSet rs = stmt.executeQuery(_sql);) {
                while( rs.next() ) {
                    Message event = resultSetToItem(rs);
                    messages.add(event);
                }
            }
            return null;
        });
        return messages;
    }
297788
def limit(self, v):
        
        if not (v is None or isinstance(v, six.integer_types)):
            raise TypeError
        if v == self._limit:
            return self

        if v < 0:
            raise QueryException("Negative limit is not allowed")

        clone = copy.deepcopy(self)
        clone._limit = v
        return clone
1185375
@SuppressWarnings("fallthrough")
    protected int handleGetLimit(int field, int limitType) {
        switch (field) {
        case ERA:
            if (limitType == MINIMUM || limitType == GREATEST_MINIMUM) {
                return 0;
            }
            return CURRENT_ERA;
        case YEAR:
        {
            switch (limitType) {
            case MINIMUM:
            case GREATEST_MINIMUM:
                return 1;
            case LEAST_MAXIMUM:
                return 1;
            case MAXIMUM:
                return super.handleGetLimit(field, MAXIMUM) - ERAS[CURRENT_ERA*3];
            }
            //Fall through to the default if not handled above
        }
        default:
            return super.handleGetLimit(field, limitType);
        }
    }
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;
	}
703621
def get_find_all_query(self, table_name, constraints=None, *, columns=None, order_by=None,
                         limiting=(None, None)):
    
    where, params = self.parse_constraints(constraints)

    if columns:
      if isinstance(columns, str):
        pass
      else:
        columns = ", ".join(columns)
    else:
      columns = "*"

    if order_by:
      order = " order by {0}".format(order_by)
    else:
      order = ""

    paging = ""
    if limiting is not None:
      limit, offset = limiting
      if limit is not None:
        paging += " limit {0}".format(limit)
      if offset is not None:
        paging += " offset {0}".format(offset)

    return ("select {0} from {1} where {2}{3}{4}".format(
      columns,
      table_name,
      where or "1 = 1",
      order,
      paging
    ), params)
1231621
private void _buildLimit(
                    final Limit limit,
                    final StringBuilder stmt
                    )
    {
        if (limit == null) {
            return;
        }

        stmt.append( _LIMIT_ );
        stmt.append( limit.getCount() );
        stmt.append( _OFFSET_ );
        stmt.append( limit.getOffset() );
    }
236284
public List<T> limit(int limit) {
        return ifReturn(Anima.of().isUseSQLLimit(),
                () -> {
                    isSQLLimit = true;
                    paramValues.add(limit);
                    return all();
                },
                () -> {
                    List<T> all = all();
                    return ifReturn(all.size() > limit,
                            all.stream().limit(limit).collect(toList()),
                            all);
                });
    }
389169
private void processAlterTableAddLimitConstraint(Table table, HsqlName name) {
        boolean isAutogeneratedName = false;
        if (name == null) {
            name = database.nameManager.newAutoName("LIMIT",
                    table.getSchemaName(), table.getName(),
                    SchemaObject.CONSTRAINT);
            isAutogeneratedName = true;
        }

        Constraint c = new Constraint(name, isAutogeneratedName, null, Constraint.LIMIT);

        readLimitConstraintCondition(c);
        session.commit(false);

        TableWorks tableWorks = new TableWorks(session, table);
        tableWorks.addLimitConstraint(c);
    }
1217567
public final void mLIMIT() throws RecognitionException {
		try {
			int _type = LIMIT;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// druidG.g:642:7: ( ( 'LIMIT' | 'limit' ) )
			// druidG.g:642:9: ( 'LIMIT' | 'limit' )
			{
			// druidG.g:642:9: ( 'LIMIT' | 'limit' )
			int alt30=2;
			int LA30_0 = input.LA(1);
			if ( (LA30_0=='L') ) {
				alt30=1;
			}
			else if ( (LA30_0=='l') ) {
				alt30=2;
			}

			else {
				NoViableAltException nvae =
					new NoViableAltException("", 30, 0, input);
				throw nvae;
			}

			switch (alt30) {
				case 1 :
					// druidG.g:642:10: 'LIMIT'
					{
					match("LIMIT"); 

					}
					break;
				case 2 :
					// druidG.g:642:20: 'limit'
					{
					match("limit"); 

					}
					break;

			}

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
1178807
private Statement compileAlterTableDropLimit(Table t) {

        HsqlName readName  = null;
        HsqlName writeName = null;
        boolean  cascade   = false;

        if (token.tokenType == Tokens.RESTRICT) {
            read();
        } else if (token.tokenType == Tokens.CASCADE) {
            read();

            cascade = true;
        }

        SchemaObject object = t.getLimitConstraint();
        if (object == null) {
            throw Error.error(ErrorCode.X_42501);
        }

        if (cascade) {
            writeName = database.getCatalogName();
        } else {
            writeName = t.getName();
        }

        Object[] args = new Object[] {
            object.getName(), Integer.valueOf(SchemaObject.CONSTRAINT),
            Boolean.valueOf(cascade), Boolean.valueOf(false)
        };
        String sql = getLastPart();

        return new StatementSchema(sql, StatementTypes.DROP_CONSTRAINT, args,
                                   readName, writeName);
    }