~ubuntu-branches/ubuntu/precise/libdbd-pg-perl/precise

« back to all changes in this revision

Viewing changes to dbdimp.c

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2008-12-15 20:20:37 UTC
  • mfrom: (1.1.18 upstream) (4.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20081215202037-zey31ccjr422db1b
Tags: 2.11.7-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
  $Id: dbdimp.c 12119 2008-11-30 22:06:55Z turnstep $
 
3
  $Id: dbdimp.c 12153 2008-12-12 16:46:21Z turnstep $
4
4
 
5
5
  Copyright (c) 2002-2008 Greg Sabino Mullane and others: see the Changes file
6
6
  Portions Copyright (c) 2002 Jeffrey W. Baker
1500
1500
 
1501
1501
        /* Builds the "segment" and "placeholder" structures for a statement handle */
1502
1502
 
 
1503
        D_imp_dbh_from_sth;
 
1504
 
1503
1505
        STRLEN currpos; /* Where we currently are in the statement string */
1504
1506
 
1505
1507
        STRLEN sectionstart, sectionstop; /* Borders of current section */
1524
1526
 
1525
1527
        char * dollarstring = NULL; /* Dynamic string between $$ in dollar quoting */
1526
1528
 
 
1529
        char standard_conforming_strings = 1; /* Status 0=on 1=unknown -1=off */
 
1530
 
1527
1531
        STRLEN xlen; /* Because "x" is too hard to search for */
1528
1532
 
1529
1533
        int xint;
1602
1606
                if ('\'' == ch || '"' == ch) {
1603
1607
                        quote = ch;
1604
1608
                        backslashes = 0;
 
1609
                        if ('\'' == ch && 1 == standard_conforming_strings) {
 
1610
                                const char * scs = PQparameterStatus(imp_dbh->conn,"standard_conforming_strings");
 
1611
                                standard_conforming_strings = (NULL==scs ? 1 : strncmp(scs,"on",2));
 
1612
                        }
 
1613
 
1605
1614
                        /* Go until ending quote character (unescaped) or end of string */
1606
1615
                        while (quote && ++currpos && (ch = *statement++)) {
1607
1616
                                /* 1.1 : single quotes have no meaning in double-quoted sections and vice-versa */
1608
1617
                                /* 1.2 : backslashed quotes do not end the section */
1609
 
                                if (ch == quote && (0==(backslashes&1))) {
 
1618
                                /* 1.2.1 : backslashes have no meaning in double quoted sections */
 
1619
                                /* 1.2.2 : if standard_confirming_strings is set, ignore backslashes in single quotes */
 
1620
                                if (ch == quote && (quote == '"' || 0==(backslashes&1))) {
1610
1621
                                        quote = 0;
1611
1622
                                }
1612
 
                                else if ('\\' == ch) 
1613
 
                                        backslashes++;
 
1623
                                else if ('\\' == ch) {
 
1624
                                        if (quote == '"' || standard_conforming_strings)
 
1625
                                                backslashes++;
 
1626
                                }
1614
1627
                                else
1615
1628
                                        backslashes = 0;
1616
1629
                        }
1627
1640
 
1628
1641
                /* 2: A comment block: */
1629
1642
                if (('-' == ch && '-' == *statement) ||
1630
 
                        ('/' == ch && '/' == *statement) ||
1631
1643
                        ('/' == ch && '*' == *statement)
1632
1644
                        ) {
1633
1645
                        quote = *statement;
1634
1646
                        /* Go until end of comment (may be newline) or end of the string */
1635
1647
                        while (quote && ++currpos && (ch = *statement++)) {
1636
 
                                /* 2.1: dashdash and slashslash only terminate at newline */
1637
 
                                if (('-' == quote || '/' == quote) && '\n' == ch) {
 
1648
                                /* 2.1: dashdash only terminates at newline */
 
1649
                                if ('-' == quote && '\n' == ch) {
1638
1650
                                        quote=0;
1639
1651
                                }
1640
1652
                                /* 2.2: slashstar ends with a matching starslash */
1655
1667
                } /* end comment section */
1656
1668
 
1657
1669
                /* 3: advanced dollar quoting - only if the backend is version 8 or higher */
1658
 
                if (version >= 80000 && '$' == ch && (*statement == '$' || *statement >= 'A')) {
1659
 
                        /* Unlike PG, we allow a little more latitude in legal characters - anything >= 65 can be used */
 
1670
                if (version >= 80000 && '$' == ch && 
 
1671
                        (*statement == '$' 
 
1672
                         || *statement == '_'
 
1673
                         || (*statement >= 'A' && *statement <= 'Z') 
 
1674
                         || (*statement >= 'a' && *statement <= 'z'))) {
 
1675
                        /* "SQL identifiers must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) 
 
1676
                or an underscore (_). Subsequent characters in an identifier or key word can be letters, underscores, 
 
1677
                digits (0-9), or dollar signs ($)
 
1678
                        */
 
1679
                        /* Postgres technically allows \200-\377 as well, but we don't */
1660
1680
                        sectionsize = 0; /* How far from the first dollar sign are we? */
1661
1681
                        found = 0; /* Have we found the end of the dollarquote? */
1662
1682
 
1664
1684
                        while ((ch = *statement++)) {
1665
1685
 
1666
1686
                                sectionsize++;
 
1687
                                if ('$' == ch) {
 
1688
                                        found = DBDPG_TRUE;
 
1689
                                        break;
 
1690
                                }
 
1691
 
1667
1692
                                /* If we hit an invalid character, bail out */
1668
 
                                if (ch <= 32 || (ch >= '0' && ch <= '9')) {
1669
 
                                        break;
1670
 
                                }
1671
 
                                if ('$' == ch) {
1672
 
                                        found = DBDPG_TRUE;
 
1693
                                if (ch <= 47 
 
1694
                                        || (ch >= 58 && ch <= 64)
 
1695
                                        || (ch >= 91 && ch <= 94)
 
1696
                                        || ch == 96
 
1697
                                        || (ch >= 123)) {
1673
1698
                                        break;
1674
1699
                                }
1675
1700
                        } /* end first scan */