~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/libsvn_subr/sqlite.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "private/svn_atomic.h"
38
38
#include "private/svn_skel.h"
39
39
#include "private/svn_token.h"
 
40
#ifdef WIN32
 
41
#include "private/svn_io_private.h"
 
42
#include "private/svn_utf_private.h"
 
43
#endif
 
44
 
 
45
#ifdef SVN_UNICODE_NORMALIZATION_FIXES
 
46
#include "private/svn_utf_private.h"
 
47
#include "private/svn_string_private.h"
 
48
#endif /* SVN_UNICODE_NORMALIZATION_FIXES */
40
49
 
41
50
#ifdef SQLITE3_DEBUG
42
51
#include "private/svn_debug.h"
60
69
#error SQLite is too old -- version 3.7.12 is the minimum required version
61
70
#endif
62
71
 
 
72
#ifndef SQLITE_DETERMINISTIC
 
73
#define SQLITE_DETERMINISTIC 0
 
74
#endif
 
75
 
 
76
#ifdef SVN_UNICODE_NORMALIZATION_FIXES
 
77
/* Limit the length of a GLOB or LIKE pattern. */
 
78
#ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
 
79
# define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
 
80
#endif
 
81
#endif /* SVN_UNICODE_NORMALIZATION_FIXES */
 
82
 
63
83
const char *
64
84
svn_sqlite__compiled_version(void)
65
85
{
97
117
}
98
118
#endif
99
119
 
 
120
#if defined(SVN_DEBUG) && defined(SQLITE_CONFIG_LOG)
 
121
static void
 
122
sqlite_error_log(void* baton, int err, const char* msg)
 
123
{
 
124
  fprintf(SVN_DBG_OUTPUT, "DBG: sqlite[S%d]: %s\n", err, msg);
 
125
}
 
126
#endif
 
127
 
 
128
void
 
129
svn_sqlite__dbg_enable_errorlog(void)
 
130
{
 
131
#if defined(SVN_DEBUG) && defined(SQLITE_CONFIG_LOG)
 
132
  sqlite3_config(SQLITE_CONFIG_LOG, sqlite_error_log, (void*)NULL /* baton */);
 
133
#endif
 
134
}
 
135
 
 
136
 
100
137
struct svn_sqlite__db_t
101
138
{
102
139
  sqlite3 *db3;
104
141
  int nbr_statements;
105
142
  svn_sqlite__stmt_t **prepared_stmts;
106
143
  apr_pool_t *state_pool;
 
144
 
 
145
#ifdef SVN_UNICODE_NORMALIZATION_FIXES
 
146
  /* Buffers for SQLite extensoins. */
 
147
  svn_membuf_t sqlext_buf1;
 
148
  svn_membuf_t sqlext_buf2;
 
149
  svn_membuf_t sqlext_buf3;
 
150
#endif /* SVN_UNICODE_NORMALIZATION_FIXES */
107
151
};
108
152
 
109
153
struct svn_sqlite__stmt_t
145
189
                             sqlite3_errmsg((db)->db3));          \
146
190
} while (0)
147
191
 
 
192
#define SQLITE_ERR_CLOSE(x, db, pool) do                          \
 
193
{                                                                 \
 
194
  int sqlite_err__temp = (x);                                     \
 
195
  if (sqlite_err__temp != SQLITE_OK)                              \
 
196
    {                                                             \
 
197
      const char *sqlite_err__msg                                 \
 
198
        = apr_pstrdup(pool, sqlite3_errmsg((db)->db3));           \
 
199
      return svn_error_compose_create(                            \
 
200
           svn_error_createf(SQLITE_ERROR_CODE(sqlite_err__temp), \
 
201
                             NULL, "sqlite[S%d]: %s",             \
 
202
                             sqlite_err__temp, sqlite_err__msg),  \
 
203
           svn_sqlite__close(db));                                \
 
204
    }                                                             \
 
205
} while (0)
 
206
 
148
207
#define SQLITE_ERR_MSG(x, msg) do                                \
149
208
{                                                                \
150
209
  int sqlite_err__temp = (x);                                    \
154
213
                             sqlite_err__temp, msg);             \
155
214
} while (0)
156
215
 
 
216
#define SVN_ERR_CLOSE(x, db) do                                       \
 
217
{                                                                     \
 
218
  svn_error_t *svn__err = (x);                                        \
 
219
  if (svn__err)                                                       \
 
220
    return svn_error_compose_create(svn__err, svn_sqlite__close(db)); \
 
221
} while (0)
 
222
 
157
223
 
158
224
/* Time (in milliseconds) to wait for sqlite locks before giving up. */
159
225
#define BUSY_TIMEOUT 10000
688
754
svn_error_t *
689
755
svn_sqlite__reset(svn_sqlite__stmt_t *stmt)
690
756
{
 
757
  /* No need to reset again after a first attempt */
 
758
  stmt->needs_reset = FALSE;
 
759
 
 
760
  /* Clear bindings first, as there are no documented reasons
 
761
     why this would ever fail, but keeping variable bindings
 
762
     when reset is not what we expect. */
 
763
  SQLITE_ERR(sqlite3_clear_bindings(stmt->s3stmt), stmt->db);
 
764
 
 
765
  /* Reset last, as this *will* fail if the statement failed since
 
766
     the last time it was reset, while reporting just the same failure.
 
767
     (In this case the statement is also properly reset).
 
768
 
 
769
     See the sqlite3_reset() documentation for more details. */
691
770
  SQLITE_ERR(sqlite3_reset(stmt->s3stmt), stmt->db);
692
 
  SQLITE_ERR(sqlite3_clear_bindings(stmt->s3stmt), stmt->db);
693
 
  stmt->needs_reset = FALSE;
694
771
  return SVN_NO_ERROR;
695
772
}
696
773
 
754
831
}
755
832
 
756
833
static svn_error_t *
757
 
internal_open(sqlite3 **db3, const char *path, svn_sqlite__mode_t mode,
758
 
              apr_pool_t *scratch_pool)
 
834
internal_open(svn_sqlite__db_t *db, const char *path, svn_sqlite__mode_t mode,
 
835
              apr_int32_t timeout, apr_pool_t *scratch_pool)
759
836
{
760
837
  {
761
838
    int flags;
789
866
           We simply want umask permissions. */
790
867
        SVN_ERR(svn_io_check_path(path, &kind, scratch_pool));
791
868
        if (kind == svn_node_none)
792
 
          SVN_ERR(svn_io_file_create(path, "", scratch_pool));
 
869
          {
 
870
            /* Another thread may have created the file, that's OK. */
 
871
            svn_error_t *err = svn_io_file_create_empty(path, scratch_pool);
 
872
            if (err && !APR_STATUS_IS_EEXIST(err->apr_err))
 
873
              return svn_error_trace(err);
 
874
            svn_error_clear(err);
 
875
          }
793
876
      }
794
877
#endif
795
878
 
796
879
    /* Open the database. Note that a handle is returned, even when an error
797
880
       occurs (except for out-of-memory); thus, we can safely use it to
798
 
       extract an error message and construct an svn_error_t. */
 
881
       extract an error message and construct an svn_error_t.  SQLite always
 
882
       requires sqlite3_close() after sqlite3_open_v2() while Subversion
 
883
       typically does not require close() after an open() that returns an
 
884
       error.  So we must ensure we close the handle if this function, or
 
885
       the caller svn_sqlite__open, returns an error to the application. */
799
886
    {
800
 
      /* We'd like to use SQLITE_ERR here, but we can't since it would
801
 
         just return an error and leave the database open.  So, we need to
802
 
         do this manually. */
 
887
      const char *vFs = NULL;
 
888
 
 
889
#if defined(WIN32) && SQLITE_VERSION_AT_LEAST(3, 8, 1)
 
890
      if (strlen(path) > 248)
 
891
        {
 
892
          WCHAR *win_path;
 
893
          vFs = "win32-longpath"; /* Enable long paths in sqlite */
 
894
 
 
895
          /* Long paths must be absolute */
 
896
          if (!svn_dirent_is_absolute(path))
 
897
            SVN_ERR(svn_dirent_get_absolute(&path, path, scratch_pool));
 
898
 
 
899
          /* Convert the path to a properly canonicalized \\?\C:\long\path */
 
900
          SVN_ERR(svn_io__utf8_to_unicode_longpath(&win_path, path,
 
901
                                                   scratch_pool));
 
902
 
 
903
          /* And convert it back to UTF-8 because there is no
 
904
              sqlite3_open16_v2() yet */
 
905
          SVN_ERR(svn_utf__win32_utf16_to_utf8(&path, win_path, NULL,
 
906
                                               scratch_pool));
 
907
        }
 
908
#endif
 
909
 
803
910
      /* ### SQLITE_CANTOPEN */
804
 
      int err_code = sqlite3_open_v2(path, db3, flags, NULL);
805
 
      if (err_code != SQLITE_OK)
806
 
        {
807
 
          /* Save the error message before closing the SQLite handle. */
808
 
          char *msg = apr_pstrdup(scratch_pool, sqlite3_errmsg(*db3));
809
 
 
810
 
          /* We don't catch the error here, since we care more about the open
811
 
             error than the close error at this point. */
812
 
          sqlite3_close(*db3);
813
 
 
814
 
          SQLITE_ERR_MSG(err_code, msg);
815
 
        }
 
911
      SQLITE_ERR_CLOSE(sqlite3_open_v2(path, &db->db3, flags, vFs),
 
912
                       db, scratch_pool);
816
913
    }
817
914
  }
818
915
 
 
916
  if (timeout <= 0)
 
917
    timeout = BUSY_TIMEOUT;
 
918
 
819
919
  /* Retry until timeout when database is busy. */
820
 
  SQLITE_ERR_MSG(sqlite3_busy_timeout(*db3, BUSY_TIMEOUT),
821
 
                 sqlite3_errmsg(*db3));
 
920
  SQLITE_ERR_CLOSE(sqlite3_busy_timeout(db->db3, timeout),
 
921
                   db, scratch_pool);
822
922
 
823
923
  return SVN_NO_ERROR;
824
924
}
838
938
  if (db->db3 == NULL)
839
939
    return APR_SUCCESS;
840
940
 
841
 
  /* Finalize any existing prepared statements. */
842
 
  for (i = 0; i < db->nbr_statements; i++)
 
941
  /* Finalize any prepared statements. */
 
942
  if (db->prepared_stmts)
843
943
    {
844
 
      if (db->prepared_stmts[i])
 
944
      for (i = 0; i < db->nbr_statements + STMT_INTERNAL_LAST; i++)
845
945
        {
846
 
          if (db->prepared_stmts[i]->needs_reset)
 
946
          if (db->prepared_stmts[i])
847
947
            {
 
948
              if (i < db->nbr_statements
 
949
                  && db->prepared_stmts[i]->needs_reset)
 
950
                {
848
951
#ifdef SVN_DEBUG
849
 
              const char *stmt_text = db->statement_strings[i];
850
 
              stmt_text = stmt_text; /* Provide value for debugger */
 
952
                  const char *stmt_text = db->statement_strings[i];
 
953
                  SVN_UNUSED(stmt_text);
851
954
 
852
 
              SVN_ERR_MALFUNCTION_NO_RETURN();
 
955
                  SVN_ERR_MALFUNCTION_NO_RETURN();
853
956
#else
 
957
                  err = svn_error_compose_create(err,
 
958
                            svn_sqlite__reset(db->prepared_stmts[i]));
 
959
#endif
 
960
                }
854
961
              err = svn_error_compose_create(
855
 
                            err,
856
 
                            svn_sqlite__reset(db->prepared_stmts[i]));
857
 
#endif
 
962
                        svn_sqlite__finalize(db->prepared_stmts[i]), err);
858
963
            }
859
 
          err = svn_error_compose_create(
860
 
                        svn_sqlite__finalize(db->prepared_stmts[i]), err);
861
 
        }
862
 
    }
863
 
  /* And finalize any used internal statements */
864
 
  for (; i < db->nbr_statements + STMT_INTERNAL_LAST; i++)
865
 
    {
866
 
      if (db->prepared_stmts[i])
867
 
        {
868
 
          err = svn_error_compose_create(
869
 
                        svn_sqlite__finalize(db->prepared_stmts[i]), err);
870
964
        }
871
965
    }
872
966
 
888
982
  return APR_SUCCESS;
889
983
}
890
984
 
 
985
#ifdef SVN_UNICODE_NORMALIZATION_FIXES
 
986
/* Unicode normalizing collation for WC paths */
 
987
static int
 
988
collate_ucs_nfd(void *baton,
 
989
                int len1, const void *key1,
 
990
                int len2, const void *key2)
 
991
{
 
992
  svn_sqlite__db_t *db = baton;
 
993
  int result;
 
994
 
 
995
  if (svn_utf__normcmp(key1, len1, key2, len2,
 
996
                       &db->sqlext_buf1, &db->sqlext_buf2, &result))
 
997
    {
 
998
      /* There is really nothing we can do here if an error occurs
 
999
         during Unicode normalizetion, and attempting to recover could
 
1000
         result in the wc.db index being corrupted. Presumably this
 
1001
         can only happen if the index already contains invalid UTF-8
 
1002
         strings, which should never happen in any case ... */
 
1003
      SVN_ERR_MALFUNCTION_NO_RETURN();
 
1004
    }
 
1005
 
 
1006
  return result;
 
1007
}
 
1008
 
 
1009
static void
 
1010
glob_like_ucs_nfd_common(sqlite3_context *context,
 
1011
                         int argc, sqlite3_value **argv,
 
1012
                         svn_boolean_t sql_like)
 
1013
{
 
1014
  svn_sqlite__db_t *const db = sqlite3_user_data(context);
 
1015
 
 
1016
  const char *const pattern = (void*)sqlite3_value_text(argv[0]);
 
1017
  const apr_size_t pattern_len = sqlite3_value_bytes(argv[0]);
 
1018
  const char *const string = (void*)sqlite3_value_text(argv[1]);
 
1019
  const apr_size_t string_len = sqlite3_value_bytes(argv[1]);
 
1020
 
 
1021
  const char *escape = NULL;
 
1022
  apr_size_t escape_len = 0;
 
1023
 
 
1024
  svn_boolean_t match;
 
1025
  svn_error_t *err;
 
1026
 
 
1027
  if (pattern_len > SQLITE_MAX_LIKE_PATTERN_LENGTH)
 
1028
    {
 
1029
      sqlite3_result_error(context, "LIKE or GLOB pattern too complex", -1);
 
1030
      return;
 
1031
    }
 
1032
 
 
1033
  if (argc == 3 && sql_like)
 
1034
    {
 
1035
      escape = (void*)sqlite3_value_text(argv[2]);
 
1036
      escape_len = sqlite3_value_bytes(argv[2]);
 
1037
    }
 
1038
 
 
1039
  if (pattern && string)
 
1040
    {
 
1041
      err = svn_utf__glob(pattern, pattern_len, string, string_len,
 
1042
                          escape, escape_len, sql_like,
 
1043
                          &db->sqlext_buf1, &db->sqlext_buf2, &db->sqlext_buf3,
 
1044
                          &match);
 
1045
 
 
1046
      if (err)
 
1047
        {
 
1048
          const char *errmsg;
 
1049
          svn_membuf__ensure(&db->sqlext_buf1, 512);
 
1050
          errmsg = svn_err_best_message(err,
 
1051
                                        db->sqlext_buf1.data,
 
1052
                                        db->sqlext_buf1.size - 1);
 
1053
          svn_error_clear(err);
 
1054
          sqlite3_result_error(context, errmsg, -1);
 
1055
          return;
 
1056
        }
 
1057
 
 
1058
      sqlite3_result_int(context, match);
 
1059
    }
 
1060
}
 
1061
 
 
1062
/* Unicode normalizing implementation of GLOB */
 
1063
static void
 
1064
glob_ucs_nfd(sqlite3_context *context,
 
1065
             int argc, sqlite3_value **argv)
 
1066
{
 
1067
  glob_like_ucs_nfd_common(context, argc, argv, FALSE);
 
1068
}
 
1069
 
 
1070
/* Unicode normalizing implementation of LIKE */
 
1071
static void
 
1072
like_ucs_nfd(sqlite3_context *context,
 
1073
             int argc, sqlite3_value **argv)
 
1074
{
 
1075
  glob_like_ucs_nfd_common(context, argc, argv, TRUE);
 
1076
}
 
1077
#endif /* SVN_UNICODE_NORMALIZATION_FIXES */
891
1078
 
892
1079
svn_error_t *
893
1080
svn_sqlite__open(svn_sqlite__db_t **db, const char *path,
894
1081
                 svn_sqlite__mode_t mode, const char * const statements[],
895
1082
                 int unused1, const char * const *unused2,
 
1083
                 apr_int32_t timeout,
896
1084
                 apr_pool_t *result_pool, apr_pool_t *scratch_pool)
897
1085
{
898
1086
  SVN_ERR(svn_atomic__init_once(&sqlite_init_state,
900
1088
 
901
1089
  *db = apr_pcalloc(result_pool, sizeof(**db));
902
1090
 
903
 
  SVN_ERR(internal_open(&(*db)->db3, path, mode, scratch_pool));
 
1091
  SVN_ERR(internal_open(*db, path, mode, timeout, scratch_pool));
904
1092
 
905
1093
#if SQLITE_VERSION_NUMBER >= 3008000 && SQLITE_VERSION_NUMBER < 3009000
906
1094
  /* disable SQLITE_ENABLE_STAT3/4 from 3.8.1 - 3.8.3 (but not 3.8.3.1+)
914
1102
    }
915
1103
#endif
916
1104
 
 
1105
#ifdef SVN_UNICODE_NORMALIZATION_FIXES
 
1106
  /* Create extension buffers with space for 200 UCS-4 characters. */
 
1107
  svn_membuf__create(&(*db)->sqlext_buf1, 800, result_pool);
 
1108
  svn_membuf__create(&(*db)->sqlext_buf2, 800, result_pool);
 
1109
  svn_membuf__create(&(*db)->sqlext_buf3, 800, result_pool);
 
1110
 
 
1111
  /* Register collation and LIKE and GLOB operator replacements. */
 
1112
  SQLITE_ERR_CLOSE(sqlite3_create_collation((*db)->db3,
 
1113
                                            "svn-ucs-nfd", SQLITE_UTF8,
 
1114
                                            *db, collate_ucs_nfd),
 
1115
                   db, scratch_pool);
 
1116
  /* ### Is it really necessary to override these functions?
 
1117
         I would assume the default implementation to be collation agnostic?
 
1118
         And otherwise our implementation should be...
 
1119
 
 
1120
         The default implementation is in some cases index backed, while our
 
1121
         implementation can't be. With an index based on the collation it could
 
1122
         be. */
 
1123
  SQLITE_ERR_CLOSE(sqlite3_create_function((*db)->db3, "glob", 2,
 
1124
                                           SQLITE_UTF8 | SQLITE_DETERMINISTIC,
 
1125
                                           *db, glob_ucs_nfd, NULL, NULL),
 
1126
                   db, scratch_pool);
 
1127
  SQLITE_ERR_CLOSE(sqlite3_create_function((*db)->db3, "like", 2,
 
1128
                                           SQLITE_UTF8 | SQLITE_DETERMINISTIC,
 
1129
                                           *db, like_ucs_nfd, NULL, NULL),
 
1130
                   db, scratch_pool);
 
1131
  SQLITE_ERR_CLOSE(sqlite3_create_function((*db)->db3, "like", 3,
 
1132
                                           SQLITE_UTF8 | SQLITE_DETERMINISTIC,
 
1133
                                           *db, like_ucs_nfd, NULL, NULL),
 
1134
                   db, scratch_pool);
 
1135
#endif /* SVN_UNICODE_NORMALIZATION_FIXES */
 
1136
 
917
1137
#ifdef SQLITE3_DEBUG
918
1138
  sqlite3_trace((*db)->db3, sqlite_tracer, (*db)->db3);
919
1139
#endif
921
1141
  sqlite3_profile((*db)->db3, sqlite_profiler, (*db)->db3);
922
1142
#endif
923
1143
 
924
 
  /* ### simplify this. remnants of some old SQLite compat code.  */
925
 
  {
926
 
    int ignored_err = SQLITE_OK;
927
 
 
928
 
    SVN_ERR(exec_sql2(*db, "PRAGMA case_sensitive_like=1;", ignored_err));
929
 
  }
930
 
 
931
 
  SVN_ERR(exec_sql(*db,
 
1144
  SVN_ERR_CLOSE(exec_sql(*db,
 
1145
              /* The default behavior of the LIKE operator is to ignore case
 
1146
                 for ASCII characters. Hence, by default 'a' LIKE 'A' is true.
 
1147
                 The case_sensitive_like pragma installs a new application-
 
1148
                 defined LIKE function that is either case sensitive or
 
1149
                 insensitive depending on the value of the case_sensitive_like
 
1150
                 pragma. */
 
1151
              "PRAGMA case_sensitive_like=1;"
932
1152
              /* Disable synchronization to disable the explicit disk flushes
933
1153
                 that make Sqlite up to 50 times slower; especially on small
934
1154
                 transactions.
951
1171
                 affects application(read: Subversion) performance/behavior. */
952
1172
              "PRAGMA foreign_keys=OFF;"      /* SQLITE_DEFAULT_FOREIGN_KEYS*/
953
1173
              "PRAGMA locking_mode = NORMAL;" /* SQLITE_DEFAULT_LOCKING_MODE */
954
 
              ));
 
1174
              "PRAGMA journal_mode = TRUNCATE;"
 
1175
              ),
 
1176
                *db);
955
1177
 
956
1178
#if defined(SVN_DEBUG)
957
1179
  /* When running in debug mode, enable the checking of foreign key
958
1180
     constraints.  This has possible performance implications, so we don't
959
1181
     bother to do it for production...for now. */
960
 
  SVN_ERR(exec_sql(*db, "PRAGMA foreign_keys=ON;"));
 
1182
  SVN_ERR_CLOSE(exec_sql(*db, "PRAGMA foreign_keys=ON;"),
 
1183
                *db);
961
1184
#endif
962
1185
 
963
1186
#ifdef SVN_SQLITE_REVERSE_UNORDERED_SELECTS
965
1188
     clause to emit their results in the reverse order of what they normally
966
1189
     would.  This can help detecting invalid assumptions about the result
967
1190
     order.*/
968
 
  SVN_ERR(exec_sql(*db, "PRAGMA reverse_unordered_selects=ON;"));
 
1191
  SVN_ERR_CLOSE(exec_sql(*db, "PRAGMA reverse_unordered_selects=ON;"),
 
1192
                *db);
969
1193
#endif
970
1194
 
971
1195
  /* Store temporary tables in RAM instead of in temporary files, but don't
1203
1427
  svn_sqlite__db_t *src_db;
1204
1428
 
1205
1429
  SVN_ERR(svn_sqlite__open(&src_db, src_path, svn_sqlite__mode_readonly,
1206
 
                           NULL, 0, NULL,
 
1430
                           NULL, 0, NULL, 0,
1207
1431
                           scratch_pool, scratch_pool));
1208
1432
 
1209
1433
  {
1212
1436
    int rc1, rc2;
1213
1437
 
1214
1438
    SVN_ERR(svn_sqlite__open(&dst_db, dst_path, svn_sqlite__mode_rwcreate,
1215
 
                             NULL, 0, NULL, scratch_pool, scratch_pool));
 
1439
                             NULL, 0, NULL, 0, scratch_pool, scratch_pool));
1216
1440
    backup = sqlite3_backup_init(dst_db->db3, "main", src_db->db3, "main");
1217
1441
    if (!backup)
1218
1442
      return svn_error_createf(SVN_ERR_SQLITE_ERROR, NULL,
1244
1468
 
1245
1469
  SVN_ERR(svn_sqlite__close(src_db));
1246
1470
 
 
1471
  SVN_ERR(svn_io_copy_perms(src_path, dst_path, scratch_pool));
 
1472
 
1247
1473
  return SVN_NO_ERROR;
1248
1474
}
1249
1475
 
1251
1477
{
1252
1478
  svn_sqlite__func_t func;
1253
1479
  void *baton;
1254
 
 
1255
 
  apr_pool_t *scratch_pool;
1256
1480
};
1257
1481
 
1258
1482
static void
1262
1486
{
1263
1487
  struct function_wrapper_baton_t *fwb = sqlite3_user_data(context);
1264
1488
  svn_sqlite__context_t sctx;
1265
 
  svn_sqlite__value_t **local_vals =
1266
 
                            apr_palloc(fwb->scratch_pool,
1267
 
                                       sizeof(svn_sqlite__value_t *) * argc);
1268
1489
  svn_error_t *err;
1269
 
  int i;
 
1490
  void *void_values = values;
1270
1491
 
1271
1492
  sctx.context = context;
1272
1493
 
1273
 
  for (i = 0; i < argc; i++)
1274
 
    {
1275
 
      local_vals[i] = apr_palloc(fwb->scratch_pool, sizeof(*local_vals[i]));
1276
 
      local_vals[i]->value = values[i];
1277
 
    }
1278
 
 
1279
 
  err = fwb->func(&sctx, argc, local_vals, fwb->scratch_pool);
1280
 
  svn_pool_clear(fwb->scratch_pool);
 
1494
  err = fwb->func(&sctx, argc, void_values, fwb->baton);
1281
1495
 
1282
1496
  if (err)
1283
1497
    {
1289
1503
    }
1290
1504
}
1291
1505
 
 
1506
 
1292
1507
svn_error_t *
1293
1508
svn_sqlite__create_scalar_function(svn_sqlite__db_t *db,
1294
1509
                                   const char *func_name,
1295
1510
                                   int argc,
 
1511
                                   svn_boolean_t deterministic,
1296
1512
                                   svn_sqlite__func_t func,
1297
1513
                                   void *baton)
1298
1514
{
 
1515
  int eTextRep;
1299
1516
  struct function_wrapper_baton_t *fwb = apr_pcalloc(db->state_pool,
1300
1517
                                                     sizeof(*fwb));
1301
1518
 
1302
 
  fwb->scratch_pool = svn_pool_create(db->state_pool);
1303
1519
  fwb->func = func;
1304
1520
  fwb->baton = baton;
1305
1521
 
1306
 
  SQLITE_ERR(sqlite3_create_function(db->db3, func_name, argc, SQLITE_ANY,
 
1522
  eTextRep = SQLITE_ANY;
 
1523
  if (deterministic)
 
1524
    eTextRep |= SQLITE_DETERMINISTIC;
 
1525
 
 
1526
  SQLITE_ERR(sqlite3_create_function(db->db3, func_name, argc, eTextRep,
1307
1527
                                     fwb, wrapped_func, NULL, NULL),
1308
1528
             db);
1309
1529
 
1313
1533
int
1314
1534
svn_sqlite__value_type(svn_sqlite__value_t *val)
1315
1535
{
1316
 
  return sqlite3_value_type(val->value);
 
1536
  void *v = val;
 
1537
  return sqlite3_value_type(v);
1317
1538
}
1318
1539
 
1319
1540
const char *
1320
1541
svn_sqlite__value_text(svn_sqlite__value_t *val)
1321
1542
{
1322
 
  return (const char *) sqlite3_value_text(val->value);
 
1543
  void *v = val;
 
1544
  return (const char *) sqlite3_value_text(v);
1323
1545
}
1324
1546
 
1325
1547
void
1333
1555
{
1334
1556
  sqlite3_result_int64(sctx->context, val);
1335
1557
}
 
1558
 
 
1559
void
 
1560
svn_sqlite__result_error(svn_sqlite__context_t *sctx, const char *msg, int num)
 
1561
{
 
1562
  sqlite3_result_error(sctx->context, msg, num);
 
1563
}