(x,y)` — rows strictly after the given key, in index order. * * @param string[] $key * @param array $after Values of the last row already handled. */ public static function after( TableInfo $info, string $table, array $key, array $after ): string { $cols = array(); $vals = array(); foreach ( $key as $column ) { $meta = $info->column( $table, $column ); $cols[] = Sql::ident( $column ); $vals[] = self::value( $meta ? $meta['type'] : '', (string) ( $after[ $column ] ?? '' ) ); } return '(' . implode( ',', $cols ) . ') > (' . implode( ',', $vals ) . ')'; } /** * `a = x AND b = y` for exactly one row. * * @param string[] $key * @param array $values */ public static function equals( TableInfo $info, string $table, array $key, array $values ): string { $parts = array(); foreach ( $key as $column ) { $meta = $info->column( $table, $column ); $parts[] = Sql::ident( $column ) . ' = ' . self::value( $meta ? $meta['type'] : '', (string) ( $values[ $column ] ?? '' ) ); } return implode( ' AND ', $parts ); } /** * Integers go unquoted so large BIGINT keys are never compared as floats. * Binary keys must be hex, because a quoted string may not survive the connection charset. */ private static function value( string $type, string $value ): string { if ( Sql::isIntegerType( $type ) && 1 === preg_match( '/^-?\d+$/', $value ) ) { return $value; } return Sql::literal( $value, $type ); } }