@@ -30,14 +30,18 @@ WriteStream::~WriteStream()
3030	}
3131}
3232
33- JSON:: Status WriteStream::parse (Database& database, Stream& source)
33+ Status WriteStream::parse (Database& database, Stream& source)
3434{
35- 	return  WriteStream (database).parser .parse (source);
35+ 	WriteStream writer (database);
36+ 	writer.parser .parse (source);
37+ 	return  writer.status ;
3638}
3739
38- JSON:: Status WriteStream::parse (Object& object, Stream& source)
40+ Status WriteStream::parse (Object& object, Stream& source)
3941{
40- 	return  WriteStream (object).parser .parse (source);
42+ 	WriteStream writer (object);
43+ 	writer.parser .parse (source);
44+ 	return  writer.status ;
4145}
4246
4347bool  WriteStream::startElement (const  JSON::Element& element)
@@ -46,18 +50,21 @@ bool WriteStream::startElement(const JSON::Element& element)
4650		return  true ;
4751	}
4852
49- 	auto  notInSchema = [&element]() -> bool  {
50- 		debug_e (" [JSON] '%s' not in schema" key );
53+ 	auto  notInSchema = [&]() -> bool  {
54+ 		debug_w (" [CFGDB] '%s' not in schema" key );
55+ 		status.result  = Result::formatError;
5156		return  false ;
5257	};
5358
54- 	auto  arrayExpected = [&element]() -> bool  {
55- 		debug_w (" [JSON] '%s' not an array" key );
59+ 	auto  arrayExpected = [&]() -> bool  {
60+ 		debug_w (" [CFGDB] '%s' not an array" key );
61+ 		status.result  = Result::formatError;
5662		return  false ;
5763	};
5864
59- 	auto  badSelector = [&element]() -> bool  {
60- 		debug_w (" [JSON] '%s' bad selector" key );
65+ 	auto  badSelector = [&]() -> bool  {
66+ 		debug_w (" [CFGDB] '%s' bad selector" key );
67+ 		status.result  = Result::formatError;
6168		return  false ;
6269	};
6370
@@ -66,7 +73,11 @@ bool WriteStream::startElement(const JSON::Element& element)
6673			return  notInSchema ();
6774		}
6875		const  char * value = (element.type  == JSON::Element::Type::Null) ? nullptr  : element.value ;
69- 		return  prop.setJsonValue (value, element.valueLength );
76+ 		if (!prop.setJsonValue (value, element.valueLength )) {
77+ 			status.result  = Result::formatError;
78+ 			return  false ;
79+ 		}
80+ 		return  true ;
7081	};
7182
7283	if (db && element.level  == 1 ) {
@@ -77,7 +88,7 @@ bool WriteStream::startElement(const JSON::Element& element)
7788			store.reset ();
7889			store = db->openStore (root, true );
7990			if (!store || !*store) {
80- 				//  Fatal: store is locked 
91+ 				status. result  = Result::updateConflict; 
8192				return  false ;
8293			}
8394			info[0 ] = *store;
@@ -97,7 +108,7 @@ bool WriteStream::startElement(const JSON::Element& element)
97108		auto & type = *db->typeinfo .stores [i];
98109		store = db->openStore (type, true );
99110		if (!store || !*store) {
100- 			//  Fatal: store is locked 
111+ 			status. result  = Result::updateConflict; 
101112			return  false ;
102113		}
103114		info[1 ] = Object (*store);
@@ -247,10 +258,9 @@ size_t WriteStream::write(const uint8_t* data, size_t size)
247258
248259	auto  jsonStatus = parser.parse (reinterpret_cast <const  char *>(data), size);
249260	switch (jsonStatus) {
261+ 	case  JSON::Status::Ok:
250262	case  JSON::Status::EndOfDocument:
251- 		break ;
252263	case  JSON::Status::Cancelled:
253- 		status.result  = Result::updateConflict;
254264		break ;
255265	default :
256266		status.result  = Result::formatError;
0 commit comments