This file is part of GNUnet
Copyright (C) 2017 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
* @file sq/sq_result_helper.c
const void *ret;
void **rdst = (void **) dst;
+ if (SQLITE_NULL ==
+ sqlite3_column_type (result,
+ column))
+ {
+ *rdst = NULL;
+ *dst_size = 0;
+ return GNUNET_YES;
+ }
+
if (SQLITE_BLOB !=
sqlite3_column_type (result,
column))
int have;
const void *ret;
+ if ( (0 == *dst_size) &&
+ (SQLITE_NULL ==
+ sqlite3_column_type (result,
+ column)) )
+ {
+ return GNUNET_YES;
+ }
+
if (SQLITE_BLOB !=
sqlite3_column_type (result,
column))
const char *text;
char **rdst = dst;
+ if (SQLITE_NULL ==
+ sqlite3_column_type (result,
+ column))
+ {
+ *rdst = NULL;
+ return GNUNET_OK;
+ }
if (SQLITE_TEXT !=
sqlite3_column_type (result,
column))
}
+/**
+ * Extract absolute time value from a Postgres database @a result at row @a row.
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param column column to extract data from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ * #GNUNET_YES if all results could be extracted
+ * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static int
+extract_abs_time (void *cls,
+ sqlite3_stmt *result,
+ unsigned int column,
+ size_t *dst_size,
+ void *dst)
+{
+ struct GNUNET_TIME_Absolute *u = dst;
+ struct GNUNET_TIME_Absolute t;
+
+ GNUNET_assert (sizeof (uint64_t) == *dst_size);
+ if (SQLITE_INTEGER !=
+ sqlite3_column_type (result,
+ column))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
+ column);
+ if (INT64_MAX == t.abs_value_us)
+ t = GNUNET_TIME_UNIT_FOREVER_ABS;
+ *u = t;
+ return GNUNET_OK;
+}
+
+
/**
* Absolute time expected.
*
struct GNUNET_SQ_ResultSpec
GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
{
- return GNUNET_SQ_result_spec_uint64 (&at->abs_value_us);
+ struct GNUNET_SQ_ResultSpec rs = {
+ .conv = &extract_abs_time,
+ .dst = at,
+ .dst_size = sizeof (struct GNUNET_TIME_Absolute),
+ .num_params = 1
+ };
+
+ return rs;
}
}
t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
column);
+ if (INT64_MAX == t.abs_value_us)
+ t = GNUNET_TIME_UNIT_FOREVER_ABS;
*u = GNUNET_TIME_absolute_hton (t);
return GNUNET_OK;
}
void *dst)
{
uint64_t v;
- uint32_t *u = dst;
+ uint16_t *u = dst;
GNUNET_assert (sizeof (uint16_t) == *dst_size);
if (SQLITE_INTEGER !=