d2ff84438bb573255bfe9d5ebb6322dec93ee0b1
[clsql.git] / sql / utils.cl
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:         utils.cl
6 ;;;; Purpose:      SQL utility functions
7 ;;;; Programmer:   Kevin M. Rosenberg
8 ;;;; Date Started: Mar 2002
9 ;;;;
10 ;;;; $Id: utils.cl,v 1.1 2002/03/26 14:11:59 kevin Exp $
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
20 (in-package :clsql-sys)
21
22
23 (defun float-to-sql-string (num)
24   "Convert exponent character for SQL"
25   (substitute #\e #\f (substitute #\e #\d (write-to-string num :readably t))))
26
27 (defun sql-escape-quotes (s)
28   "Escape single quotes for SQL"
29   (substitute-string-for-char s #\' "''"))
30
31 (defun substitute-string-for-char (procstr match-char subst-str) 
32 "Substitutes a string for a single matching character of a string"
33   (let ((pos (position match-char procstr)))
34     (if pos
35         (concatenate 'string
36           (subseq procstr 0 pos) subst-str
37           (substitute-string-for-char 
38            (subseq procstr (1+ pos)) match-char subst-str))
39       procstr)))
40
41