8ee2b031c6df7986a63d89a2125bd915c1167309
[clsql.git] / tests / test-internal.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:    test-internal.lisp
6 ;;;; Purpose: Tests for internal clsql functions
7 ;;;; Author:  Kevin M. Rosenberg
8 ;;;; Created: May 2004
9 ;;;;
10 ;;;; This file, part of CLSQL, is Copyright (c) 2004-2010 by Kevin M. Rosenberg
11 ;;;;
12 ;;;; CLSQL users are granted the rights to distribute and use this software
13 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
14 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
15 ;;;; *************************************************************************
16
17 (in-package #:clsql-tests)
18 (clsql-sys:file-enable-sql-reader-syntax)
19
20 (setq *rt-internal*
21   '(
22     (deftest :int/convert/1
23         (clsql-sys::prepared-sql-to-postgresql-sql "SELECT FOO FROM BAR")
24       "SELECT FOO FROM BAR")
25
26     (deftest :int/convert/2
27         (clsql-sys::prepared-sql-to-postgresql-sql "SELECT FOO FROM BAR WHERE ID=?")
28       "SELECT FOO FROM BAR WHERE ID=$1")
29
30     (deftest :int/convert/3
31         (clsql-sys::prepared-sql-to-postgresql-sql "SELECT FOO FROM \"BAR\" WHERE ID=? AND CODE=?")
32       "SELECT FOO FROM \"BAR\" WHERE ID=$1 AND CODE=$2")
33
34     (deftest :int/convert/4
35         (clsql-sys::prepared-sql-to-postgresql-sql "SELECT FOO FROM BAR WHERE ID=\"Match?\" AND CODE=?")
36       "SELECT FOO FROM BAR WHERE ID=\"Match?\" AND CODE=$1")
37
38     (deftest :int/convert/5
39         (clsql-sys::prepared-sql-to-postgresql-sql "SELECT 'FOO' FROM BAR WHERE ID='Match?''?' AND CODE=?")
40       "SELECT 'FOO' FROM BAR WHERE ID='Match?''?' AND CODE=$1")
41
42     (deftest :int/output-caching/1
43      ;; ensure that key generation and matching is working
44      ;; so that this table doesnt balloon (more than designed)
45      (list
46       (progn (clsql:sql [foo])
47              (clsql:sql [foo])
48              (hash-table-count clsql-sys::*output-hash*))
49
50       (progn (clsql:sql [foo.bar])
51              (clsql:sql [foo bar])
52              (hash-table-count clsql-sys::*output-hash*))
53       (progn (clsql:sql (clsql-sys:sql-expression
54                          :table (clsql-sys::database-identifier 'foo)
55                          :attribute (clsql-sys::database-identifier 'bar)))
56              (clsql:sql (clsql-sys:sql-expression
57                          :table (clsql-sys::database-identifier 'foo)
58                          :attribute (clsql-sys::database-identifier 'bar)))
59              (hash-table-count clsql-sys::*output-hash*)))
60      (1 2 2))
61
62     (deftest :int/output-caching/2
63      ;; ensure that we can disable the output cache and
64      ;; still have everything work
65      (let ((clsql-sys::*output-hash*))
66        (list (clsql:sql [foo]) (clsql:sql [foo]) (clsql:sql [foo.bar])))
67      ("FOO" "FOO" "FOO.BAR"))
68
69     ))
70