Rasqal RDF Query Library Manual | ||||
---|---|---|---|---|
Top | Description |
XML Schema Datetime and DecimalsXML Schema Datetime and Decimals — XML Schema datetime and arbitrary length decimal number arithmetic. |
rasqal_xsd_date; rasqal_xsd_date * rasqal_new_xsd_date (rasqal_world *world
,const char *date_string
); void rasqal_free_xsd_date (rasqal_xsd_date *d
); char * rasqal_xsd_date_to_counted_string (const rasqal_xsd_date *date
,size_t *len_p
); char * rasqal_xsd_date_to_string (const rasqal_xsd_date *d
); int rasqal_xsd_date_equals (const rasqal_xsd_date *d1
,const rasqal_xsd_date *d2
,int *incomparible_p
); int rasqal_xsd_date_compare (const rasqal_xsd_date *d1
,const rasqal_xsd_date *d2
,int *incomparible_p
); rasqal_xsd_datetime; #define RASQAL_XSD_DATETIME_NO_TZ rasqal_xsd_datetime * rasqal_new_xsd_datetime (rasqal_world *world
,const char *datetime_string
); rasqal_xsd_datetime * rasqal_new_xsd_datetime_from_timeval (rasqal_world *world
,struct timeval *tv
); rasqal_xsd_datetime * rasqal_new_xsd_datetime_from_unixtime (rasqal_world *world
,time_t secs
); rasqal_xsd_datetime * rasqal_new_xsd_datetime_from_xsd_date (rasqal_world *world
,rasqal_xsd_date *date
); void rasqal_free_xsd_datetime (rasqal_xsd_datetime *dt
); int rasqal_xsd_datetime_compare (const rasqal_xsd_datetime *dt1
,const rasqal_xsd_datetime *dt2
); int rasqal_xsd_datetime_compare2 (const rasqal_xsd_datetime *dt1
,const rasqal_xsd_datetime *dt2
,int *incomparible_p
); int rasqal_xsd_datetime_equals (const rasqal_xsd_datetime *dt1
,const rasqal_xsd_datetime *dt2
); int rasqal_xsd_datetime_equals2 (const rasqal_xsd_datetime *dt1
,const rasqal_xsd_datetime *dt2
,int *incomparible_p
); struct timeval * rasqal_xsd_datetime_get_as_timeval (rasqal_xsd_datetime *dt
); time_t rasqal_xsd_datetime_get_as_unixtime (rasqal_xsd_datetime *dt
); rasqal_xsd_decimal * rasqal_xsd_datetime_get_seconds_as_decimal (rasqal_world *world
,rasqal_xsd_datetime *dt
); char * rasqal_xsd_datetime_get_timezone_as_counted_string (rasqal_xsd_datetime *dt
,size_t *len_p
); char * rasqal_xsd_datetime_get_tz_as_counted_string (rasqal_xsd_datetime *dt
,size_t *len_p
); int rasqal_xsd_datetime_set_from_timeval (rasqal_xsd_datetime *dt
,struct timeval *tv
); int rasqal_xsd_datetime_set_from_unixtime (rasqal_xsd_datetime *dt
,time_t clock
); char * rasqal_xsd_datetime_to_counted_string (const rasqal_xsd_datetime *dt
,size_t *len_p
); char * rasqal_xsd_datetime_to_string (const rasqal_xsd_datetime *dt
); void rasqal_free_xsd_decimal (rasqal_xsd_decimal *dec
); rasqal_xsd_decimal * rasqal_new_xsd_decimal (rasqal_world *world
); typedef rasqal_xsd_decimal; int rasqal_xsd_decimal_abs (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
); int rasqal_xsd_decimal_add (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
); char * rasqal_xsd_decimal_as_counted_string (rasqal_xsd_decimal *dec
,size_t *len_p
); char * rasqal_xsd_decimal_as_string (rasqal_xsd_decimal *dec
); int rasqal_xsd_decimal_ceil (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
); int rasqal_xsd_decimal_compare (rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
); int rasqal_xsd_decimal_divide (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
); int rasqal_xsd_decimal_equals (rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
); int rasqal_xsd_decimal_floor (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
); double rasqal_xsd_decimal_get_double (rasqal_xsd_decimal *dec
); long rasqal_xsd_decimal_get_long (rasqal_xsd_decimal *dec
,int *error_p
); int rasqal_xsd_decimal_is_zero (rasqal_xsd_decimal *d
); int rasqal_xsd_decimal_multiply (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
); int rasqal_xsd_decimal_negate (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
); int rasqal_xsd_decimal_print (rasqal_xsd_decimal *dec
,FILE *stream
); int rasqal_xsd_decimal_round (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
); int rasqal_xsd_decimal_set_double (rasqal_xsd_decimal *dec
,double d
); int rasqal_xsd_decimal_set_long (rasqal_xsd_decimal *dec
,long l Param2
); int rasqal_xsd_decimal_set_string (rasqal_xsd_decimal *dec
,const char *string
); int rasqal_xsd_decimal_subtract (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
);
Classes for providing XSD datatypes for Datetimes plus Decimals with arbitrary length floating point decimals and standard operators on the Decimals suitable for SPARQL.
typedef struct { signed int year; /* the following fields are integer values not characters */ unsigned char month; unsigned char day; signed short timezone_minutes; time_t time_on_timeline; char have_tz; } rasqal_xsd_date;
XML schema date datatype (xsd:date)
Examples of timezone fields: "2010-01-02" : timezone_minutes RASQAL_XSD_DATETIME_NO_TZ, have_tz 'N' "2010-01-02Z" : timezone_minutes 0, have_tz 'Z' "2010-01-02+00:00" : timezone_minutes 0, have_tz 'Y' "2010-01-02-01:00" : timezone_minutes -60, have_tz 'Y'
year | |
month 1-12 | |
1-31 | |
minutes +/- against UTC or RASQAL_XSD_DATETIME_NO_TZ if there is no timezone in the dateTime. | |
time on timeline of first instant of date in timezone | |
timezone flag: 'Z' if Zulu, 'Y' if has other timezone offset in timezone_minutes , 'N' if there is no timezone |
rasqal_xsd_date * rasqal_new_xsd_date (rasqal_world *world
,const char *date_string
);
Constructor - make a new XSD date object from a string
|
world object |
|
XSD date string |
Returns : |
new datetime or NULL on failure |
void rasqal_free_xsd_date (rasqal_xsd_date *d
);
Destroy XSD date object.
|
date object |
char * rasqal_xsd_date_to_counted_string (const rasqal_xsd_date *date
,size_t *len_p
);
Convert a rasqal_xsd_date struct to a xsd:date lexical form string.
Caller should rasqal_free_memory()
the returned string.
See http://www.w3.org/TR/xmlschema-2/date-canonical-representation
|
date struct |
|
output length (or NULL) |
Returns : |
lexical form string or NULL on failure. |
char * rasqal_xsd_date_to_string (const rasqal_xsd_date *d
);
Convert a rasqal_xsd_date struct to a xsd:date lexical form string.
Caller should rasqal_free_memory()
the returned string.
|
date struct |
Returns : |
lexical form string or NULL on failure. |
int rasqal_xsd_date_equals (const rasqal_xsd_date *d1
,const rasqal_xsd_date *d2
,int *incomparible_p
);
Compare two XSD dates for equality.
|
first XSD date |
|
second XSD date |
|
address to store incomparable flag (or NULL) |
Returns : |
non-0 if equal. |
int rasqal_xsd_date_compare (const rasqal_xsd_date *d1
,const rasqal_xsd_date *d2
,int *incomparible_p
);
Compare two XSD dates
If the only one of the two dates have timezones, the results
may be incomparible and that will return >0 and set the
value of the int point to by incomparible_p
to non-0
|
first XSD date |
|
second XSD date |
|
address to store incomparable flag (or NULL) |
Returns : |
<0 if d1 is less than d2 , 0 if equal, >0 otherwise |
typedef struct { signed int year; unsigned char month; unsigned char day; /* the following fields are integer values not characters */ signed char hour; signed char minute; signed char second; signed int microseconds; signed short timezone_minutes; time_t time_on_timeline; char have_tz; } rasqal_xsd_datetime;
XML Schema dateTime datatype (xsd:dateTime)
Signed types are required for normalization process where a value can be negative temporarily.
Examples of timezone fields: "2010-01-02T01:02:03" : timezone_minutes RASQAL_XSD_DATETIME_NO_TZ, have_tz 'N' "2010-01-02T01:02:03Z" : timezone_minutes 0, have_tz 'Z' "2010-01-02T01:02:03+00:00" : timezone_minutes 0, have_tz 'Y' "2010-01-02T01:02:03-01:00" : timezone_minutes -60, have_tz 'Y'
year | |
month 1-12 | |
1-31 | |
hour 0-23 | |
minute 0-59 | |
second 0-60 (yes 60 is allowed for leap seconds) | |
microseconds | |
minutes +/- against UTC or RASQAL_XSD_DATETIME_NO_TZ if there is no timezone in the dateTime. | |
time on timeline | |
timezone flag: 'Z' if Zulu, 'Y' if has other timezone offset in timezone_minutes , 'N' if there is no timezone |
#define RASQAL_XSD_DATETIME_NO_TZ (9999)
Sentinel XSD Decimal timezone value indicating no timezone is present.
rasqal_xsd_datetime * rasqal_new_xsd_datetime (rasqal_world *world
,const char *datetime_string
);
Constructor - make a new XSD datetime object from a string
|
world object |
|
XSD Datetime string |
Returns : |
new datetime or NULL on failure |
rasqal_xsd_datetime * rasqal_new_xsd_datetime_from_timeval (rasqal_world *world
,struct timeval *tv
);
Constructor - make a new XSD datetime object from a timeval
|
world object |
|
pointer to struct timeval |
Returns : |
new datetime or NULL on failure |
rasqal_xsd_datetime * rasqal_new_xsd_datetime_from_unixtime (rasqal_world *world
,time_t secs
);
Constructor - make a new XSD datetime object from unixtime seconds
|
world object |
|
unixtime |
Returns : |
new datetime or NULL on failure |
rasqal_xsd_datetime * rasqal_new_xsd_datetime_from_xsd_date (rasqal_world *world
,rasqal_xsd_date *date
);
Constructor - make a new XSD datetime object from an XSD date
|
world object |
|
pointer to XSD date |
Returns : |
new datetime or NULL on failure |
void rasqal_free_xsd_datetime (rasqal_xsd_datetime *dt
);
Destroy XSD datetime object.
|
datetime object |
int rasqal_xsd_datetime_compare (const rasqal_xsd_datetime *dt1
,const rasqal_xsd_datetime *dt2
);
Compare two XSD dateTimes
Deprecated
for rasqal_xsd_datetime_compare2()
which can return the incomparible result.
|
first XSD dateTime |
|
second XSD dateTime |
Returns : |
<0 if dt1 is less than dt2 , 0 if equal, >0 otherwise |
int rasqal_xsd_datetime_compare2 (const rasqal_xsd_datetime *dt1
,const rasqal_xsd_datetime *dt2
,int *incomparible_p
);
Compare two XSD dateTimes
If the only one of the two dateTimes have timezones, the results
may be incomparible and that will return >0 and set the
value of the int point to by incomparible_p
to non-0
|
first XSD dateTime |
|
second XSD dateTime |
|
address to store incomparable flag (or NULL) |
Returns : |
<0 if dt1 is less than dt2 , 0 if equal, >0 otherwise |
int rasqal_xsd_datetime_equals (const rasqal_xsd_datetime *dt1
,const rasqal_xsd_datetime *dt2
);
Compare two XSD dateTimes for equality.
Deprecated
: for rasqal_xsd_datetime_equals2 that returns incomparibility.
|
first XSD dateTime |
|
second XSD dateTime |
Returns : |
non-0 if equal. |
int rasqal_xsd_datetime_equals2 (const rasqal_xsd_datetime *dt1
,const rasqal_xsd_datetime *dt2
,int *incomparible_p
);
Compare two XSD dateTimes for equality.
|
first XSD dateTime |
|
second XSD dateTime |
|
address to store incomparable flag (or NULL) |
Returns : |
non-0 if equal. |
struct timeval * rasqal_xsd_datetime_get_as_timeval (rasqal_xsd_datetime *dt
);
Get a datetime as struct timeval
The returned timeval must be freed by the caller such as using
rasqal_free_memory()
.
|
datetime |
Returns : |
pointer to a new timeval structure or NULL on failure |
time_t rasqal_xsd_datetime_get_as_unixtime (rasqal_xsd_datetime *dt
);
Get a datetime as unix seconds
|
datetime |
Returns : |
unix seconds or 0 if dt is NULL |
rasqal_xsd_decimal * rasqal_xsd_datetime_get_seconds_as_decimal (rasqal_world *world
,rasqal_xsd_datetime *dt
);
Get the seconds component of a dateTime as a decimal
|
world object |
|
XSD dateTime |
Returns : |
decimal object or NULL on failure |
char * rasqal_xsd_datetime_get_timezone_as_counted_string (rasqal_xsd_datetime *dt
,size_t *len_p
);
Get the timezone of a datetime as a duration format string with optional length count
The returned string is owned by the caller and must be freed
by rasqal_free_memory()
.
|
datetime |
|
pointer to store returned string length |
Returns : |
pointer to a new string or NULL on failure |
char * rasqal_xsd_datetime_get_tz_as_counted_string (rasqal_xsd_datetime *dt
,size_t *len_p
);
Get the timezone of a datetime as a timezone string
The returned string is owned by the caller and must be freed
by rasqal_free_memory()
.
|
datetime |
|
pointer to store returned string length |
Returns : |
pointer to a new string or NULL on failure |
int rasqal_xsd_datetime_set_from_timeval (rasqal_xsd_datetime *dt
,struct timeval *tv
);
Set an XSD dateTime from a struct timeval pointer
|
datetime |
|
timeval |
Returns : |
non-0 on failure |
int rasqal_xsd_datetime_set_from_unixtime (rasqal_xsd_datetime *dt
,time_t clock
);
Set an XSD dateTime from unixtime seconds
|
date time |
|
unix time in seconds |
Returns : |
non-0 on failure |
char * rasqal_xsd_datetime_to_counted_string (const rasqal_xsd_datetime *dt
,size_t *len_p
);
Convert a rasqal_xsd_datetime struct to a xsd:dateTime lexical form counted string.
Caller should rasqal_free_memory()
the returned string.
See http://www.w3.org/TR/xmlschema-2/dateTime-canonical-representation
|
datetime struct |
|
output length (or NULL) |
Returns : |
lexical form string or NULL on failure. |
char * rasqal_xsd_datetime_to_string (const rasqal_xsd_datetime *dt
);
Convert a rasqal_xsd_datetime struct to a xsd:dateTime lexical form string.
Caller should rasqal_free_memory()
the returned string.
|
datetime struct |
Returns : |
lexical form string or NULL on failure. |
void rasqal_free_xsd_decimal (rasqal_xsd_decimal *dec
);
Destroy XSD Decimal object.
|
Decimal object |
rasqal_xsd_decimal * rasqal_new_xsd_decimal (rasqal_world *world
);
Create a new XSD Decimal object.
|
rasqal world object |
Returns : |
new xsd:decimal object or NULL on failure. |
typedef struct rasqal_xsd_decimal_s rasqal_xsd_decimal;
Rasqal XSD Decimal class.
int rasqal_xsd_decimal_abs (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
);
Return the absolute value of an XSD Decimal
|
result variable |
|
argment decimal |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_add (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
);
Add two XSD Decimals and store in result XSD Decimal
|
result variable |
|
argment decimal 1 |
|
argument decimal 2 |
Returns : |
non-0 on failure |
char * rasqal_xsd_decimal_as_counted_string (rasqal_xsd_decimal *dec
,size_t *len_p
);
Get an XSD Decimal as a string lexical form with optional length.
The returned string is shared and owned by the dec
object and
must be copied. If len_p
is not NULL, the length of the returned
string is stored.
|
XSD Decimal |
|
pointer to length variable (or NULL) |
Returns : |
lexical form string or NULL on failure. |
char * rasqal_xsd_decimal_as_string (rasqal_xsd_decimal *dec
);
Get an XSD Decimal as a string lexical form.
The returned string is shared and owned by the dec
object and
must be copied.
|
XSD Decimal |
Returns : |
lexical form string or NULL on failure. |
int rasqal_xsd_decimal_ceil (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
);
Return the number with no fractional part closes to argument for an XSD Decimal
|
result variable |
|
argment decimal |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_compare (rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
);
Compare two XSD Decimals
|
first XSD decimal |
|
second XSD decimal |
Returns : |
<0 if a is less than b , 0 if equal, >1 otherwise |
int rasqal_xsd_decimal_divide (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
);
Divide two XSD Decimals and store in result XSD Decimal
If the divisor b
is 0, failure is returned
|
result variable |
|
argment decimal 1 |
|
argument decimal 2 |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_equals (rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
);
Compare two XSD Decimals for equality.
|
first XSD Decimal |
|
second XSD Decimal |
Returns : |
non-0 if equal. |
int rasqal_xsd_decimal_floor (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
);
Return the number with no fractional part closes to argument for an XSD Decimal
|
result variable |
|
argment decimal |
Returns : |
non-0 on failure |
double rasqal_xsd_decimal_get_double (rasqal_xsd_decimal *dec
);
Get an XSD Decimal as a double (may lose precision)
|
XSD Decimal |
Returns : |
double value. |
long rasqal_xsd_decimal_get_long (rasqal_xsd_decimal *dec
,int *error_p
);
Get an XSD Decimal as a long (may lose precision)
|
XSD Decimal |
|
pointer to error flag |
Returns : |
long value or 0 on failure and *error_p is non-0 |
int rasqal_xsd_decimal_is_zero (rasqal_xsd_decimal *d
);
Test if an XSD decimal is zero.
|
decimal |
Returns : |
non-0 if decimal is zero |
int rasqal_xsd_decimal_multiply (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
);
Multiply two XSD Decimals and store in result XSD Decimal
|
result variable |
|
argment decimal 1 |
|
argument decimal 2 |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_negate (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
);
Negate an XSD Decimal
|
result variable |
|
argment decimal |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_print (rasqal_xsd_decimal *dec
,FILE *stream
);
Print an XSD Decimal to a stream
|
XSD Decimal object |
|
FILE* handle to print to |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_round (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
);
Return the number with no fractional part closes to argument for an XSD Decimal
|
result variable |
|
argment decimal |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_set_double (rasqal_xsd_decimal *dec
,double d
);
Set an XSD Decimal value from a double.
|
XSD Decimal |
|
double |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_set_long (rasqal_xsd_decimal *dec
,long l Param2
);
Set an XSD Decimal value from a long.
|
XSD Decimal |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_set_string (rasqal_xsd_decimal *dec
,const char *string
);
Set an XSD Decimal value from a string lexical form
|
XSD Decimal |
|
lexical form |
Returns : |
non-0 on failure |
int rasqal_xsd_decimal_subtract (rasqal_xsd_decimal *result
,rasqal_xsd_decimal *a
,rasqal_xsd_decimal *b
);
Subtract two XSD Decimals and store in result XSD Decimal
|
result variable |
|
argment decimal 1 |
|
argument decimal 2 |
Returns : |
non-0 on failure |