Function: emacsql--expand-format-string

emacsql--expand-format-string is a byte-compiled function defined in emacsql-compiler.el.

Signature

(emacsql--expand-format-string OP EXPR ARITY ARGUMENT-COUNT)

Documentation

Create format-string for an SQL operator.

The format-string returned is intended to be used with format to create an SQL expression.

Source Code

;; Defined in ~/.emacs.d/elpa/emacsql-20261001.1544/emacsql-compiler.el
(defun emacsql--expand-format-string (op expr arity argument-count)
  "Create format-string for an SQL operator.
The format-string returned is intended to be used with `format'
to create an SQL expression."
  (and expr
       (cl-labels ((replace-operand (x) (if (eq x :operand) "%s" x))
                   (to-format-string (e) (mapconcat #'replace-operand e "")))
         (cond
          ((and (eq arity :unary) (eql argument-count 1))
           (to-format-string expr))
          ((and (eq arity :binary) (>= argument-count 2))
           (let ((result (reverse expr)))
             (dotimes (_ (- argument-count 2))
               (setq result (nconc (reverse expr) (cdr result))))
             (to-format-string (nreverse result))))
          (t (emacsql-error "Wrong number of operands for %s" op))))))