Skip to content

Commit

Permalink
Merge pull request #43 from qorelanguage/feature/2322_sql_null_support
Browse files Browse the repository at this point in the history
refs qorelanguage/qore#2322 added the EmitSqlNull constant and suppor…
  • Loading branch information
pvanek committed Oct 23, 2017
2 parents 1a7fefe + 046d111 commit 5cdf76e
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 250 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.3)
project(qore-yaml-module)

set (VERSION_MAJOR 0)
set (VERSION_MINOR 5)
set (VERSION_MINOR 7)
set (VERSION_PATCH 0)

# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Process this file with autoconf to produce a configure script.

# AC_PREREQ(2.59)
AC_INIT([qore-yaml-module], [0.6],
AC_INIT([qore-yaml-module], [0.7],
[David Nichols <david@qore.org>],
[qore-yaml-module])
AM_INIT_AUTOMAKE([no-dist-gzip dist-bzip2 tar-ustar])
Expand Down
6 changes: 5 additions & 1 deletion docs/mainpage.doxygen.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ any data = parse_yaml(yaml_str);
|date (relative)|\c !duration|\c P2M3DT10H14u|\c P2M3DT10H14u|Relative date/time values (durations) are serialized with Qore's <a href="http://en.wikipedia.org/wiki/ISO_8601#Durations">ISO-8601</a>-based format.<br><br>This tag is a custom tag used only by Qore to serialize Qore relative date/time values with YAML
|date (absolute)|\c !!timestamp|\c 2010-05-05T15:35:02.100|\c 2010-05-05T15:35:02.1+02:00|Absolute date/time values are serialized with YAML's <a href="http://yaml.org/type/timestamp.html">timestamp</a> format.<br><br>Note that qore date/time values without an explicit time zone are assumed to be in the local time zone.<br><br>When converting a YAML timestamp to a Qore date, because Qore supports only up to microsecond resolution in date/time values, any digits after microseconds are lost.
|NOTHING|\c !!null|\c NOTHING|\c null|direct serialization
|NULL|\c !!null|\c NULL|\c null|serialization to YAML null, just like \c NOTHING; will be deserialized as \c NOTHING.
|NULL|\c !!null or \c !sqlnull|\c NULL|\c null or \c !sqlnull|without @ref @ref Qore::YAML::EmitSqlNull "EmitSqlNull", serialization to YAML null, just like \c NOTHING; will be deserialized as \c NOTHING, with @ref Qore::YAML::EmitSqlNull "EmitSqlNull" will be deserialized to \c NULL.
|list|\c !!seq|\c (1, 2, "three")|\c [1, 2, "three"]|direct serialization
|hash|\c !!map|\c ("key" : 1, "other" : 2.0, "data" : "three")|\c {key: 1, other: 2.0, data: "three"}|direct serialization, although qore will maintain key order as well even though this property is only defined for an ordered map

@section yamlreleasenotes Release Notes

@subsection yaml07 yaml Module Version 0.7

- added optional support for serializing SQL NULL values with @ref Qore::YAML::EmitSqlNull "EmitSqlNull"

@subsection yaml06 yaml Module Version 0.6

- improved the description for the \c DESERIALIZATION-ERROR exception for non-deserializable message bodies from HTTP servers with error responses (<a href="https://github.com/qorelanguage/qore/issues/1033">issue 1033</a>)
Expand Down
5 changes: 4 additions & 1 deletion qore-yaml-module.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%global mod_ver 0.6
%global mod_ver 0.7

%{?_datarootdir: %global mydatarootdir %_datarootdir}
%{!?_datarootdir: %global mydatarootdir /usr/share}
Expand Down Expand Up @@ -100,6 +100,9 @@ rm -rf $RPM_BUILD_ROOT
%doc COPYING.LGPL COPYING.MIT README RELEASE-NOTES AUTHORS

%changelog
* Sat Oct 21 2017 David Nichols <david@qore.org> 0.7
- updated to version 0.7

* Wed Nov 23 2016 David Nichols <david@qore.org> 0.6
- updated to version 0.6

Expand Down
121 changes: 63 additions & 58 deletions src/QoreYamlEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
yaml Qore module
Copyright (C) 2010 - 2013 David Nichols, all rights reserved
Copyright (C) 2010 - 2017 Qore Technologies, s.r.o.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -31,6 +31,7 @@ QoreYamlEmitter::QoreYamlEmitter(QoreYamlWriteHandler &n_wh, int flags, int widt
: QoreYamlBase(n_xsink), wh(n_wh), block(flags & QYE_BLOCK_STYLE),
implicit_start_doc(!(flags & QYE_EXPLICIT_START_DOC)),
implicit_end_doc(!(flags & QYE_EXPLICIT_END_DOC)),
emit_sqlnull(flags & QYE_EMIT_SQLNULL),
yaml_ver(0) {
if (!yaml_emitter_initialize(&emitter)) {
err("unknown error initializing yaml emitter");
Expand Down Expand Up @@ -68,39 +69,43 @@ QoreYamlEmitter::QoreYamlEmitter(QoreYamlWriteHandler &n_wh, int flags, int widt
int QoreYamlEmitter::emit(const QoreValue& v) {
switch (v.getType()) {
case NT_STRING:
return emitValue(*v.get<const QoreStringNode>());
return emitValue(*v.get<const QoreStringNode>());

case NT_INT:
return emitValue(v.getAsBigInt());
return emitValue(v.getAsBigInt());

case NT_FLOAT:
return emitValue(v.getAsFloat());
return emitValue(v.getAsFloat());

case NT_NUMBER:
return emitValue(*v.get<const QoreNumberNode>());
return emitValue(*v.get<const QoreNumberNode>());

case NT_BOOLEAN:
return emitValue(v.getAsBool());
return emitValue(v.getAsBool());

case NT_LIST:
return emitValue(*v.get<const QoreListNode>());
return emitValue(*v.get<const QoreListNode>());

case NT_HASH:
return emitValue(*v.get<const QoreHashNode>());
return emitValue(*v.get<const QoreHashNode>());

case NT_DATE:
return emitValue(*v.get<const DateTimeNode>());
return emitValue(*v.get<const DateTimeNode>());

case NT_BINARY:
return emitValue(*v.get<const BinaryNode>());
return emitValue(*v.get<const BinaryNode>());

case NT_NULL:
if (emit_sqlnull)
return emitSqlNull();
// fall down to nothing

case NT_NOTHING:
return emitNull();
return emitNull();

default:
err("cannot convert Qore type '%s' to YAML", v.getTypeName());
return -1;
err("cannot convert Qore type '%s' to YAML", v.getTypeName());
return -1;
}

return 0;
Expand All @@ -115,43 +120,43 @@ int QoreYamlEmitter::emitValue(const DateTime &d) {
if (d.isRelative()) {
str.concat('P');
if (d.hasValue()) {
if (info.year)
str.sprintf("%dY", info.year);
if (info.month)
str.sprintf("%dM", info.month);
if (info.day)
str.sprintf("%dD", info.day);

bool has_t = false;

if (info.hour) {
str.sprintf("T%dH", info.hour);
has_t = true;
}
if (info.minute) {
if (!has_t) {
str.concat('T');
has_t = true;
}
str.sprintf("%dM", info.minute);
}
if (info.second) {
if (!has_t) {
str.concat('T');
has_t = true;
}
str.sprintf("%dS", info.second);
}
if (info.us) {
if (!has_t) {
str.concat('T');
has_t = true;
}
str.sprintf("%du", info.us);
}
if (info.year)
str.sprintf("%dY", info.year);
if (info.month)
str.sprintf("%dM", info.month);
if (info.day)
str.sprintf("%dD", info.day);

bool has_t = false;

if (info.hour) {
str.sprintf("T%dH", info.hour);
has_t = true;
}
if (info.minute) {
if (!has_t) {
str.concat('T');
has_t = true;
}
str.sprintf("%dM", info.minute);
}
if (info.second) {
if (!has_t) {
str.concat('T');
has_t = true;
}
str.sprintf("%dS", info.second);
}
if (info.us) {
if (!has_t) {
str.concat('T');
has_t = true;
}
str.sprintf("%du", info.us);
}
}
else
str.concat("0D");
str.concat("0D");

return emitScalar(str, QORE_YAML_DURATION_TAG);
}
Expand All @@ -163,13 +168,13 @@ int QoreYamlEmitter::emitValue(const DateTime &d) {
else {
d.format(str, "YYYY-MM-DD");
if (!info.isTimeNull() || info.secsEast()) {
// use spaces for enhanced readability
if (!info.us)
d.format(str, " HH:mm:SS.");
else if (!(info.us % 1000))
d.format(str, " HH:mm:SS.ms");
else
d.format(str, " HH:mm:SS.xx");
// use spaces for enhanced readability
if (!info.us)
d.format(str, " HH:mm:SS.");
else if (!(info.us % 1000))
d.format(str, " HH:mm:SS.ms");
else
d.format(str, " HH:mm:SS.xx");
}
}

Expand All @@ -182,9 +187,9 @@ int QoreYamlEmitter::emitValue(const DateTime &d) {
// then add a space
if (!emitter.canonical) {
if (!info.isTimeNull() || info.secsEast()) {
str.concat(' ');
// add time zone offset (or "Z")
d.format(str, "Z");
str.concat(' ');
// add time zone offset (or "Z")
d.format(str, "Z");
}
}
else
Expand Down

0 comments on commit 5cdf76e

Please sign in to comment.