Hi,
As far as I can remember when using early versions from my client-software, the main difference in output after sending \04 or \1F to the database, was that in the latter case the output was preceded with XDM Meta data.
# Full query_txt <- "for $i in 1 to 2 return <xml>Text { $i }</xml>" query_obj <- Query(Session, query_txt) result <- Full(query_obj)
resulted in: "0b" "<xml>Text 1</xml>" "0b" "<xml>Text 2</xml>"
# Iterate over query query2 <- "for $i in 3 to 4 return <xml>Iter { $i }</xml>" query_iterate <- Query(Session, query2) # <== Alternative call to query-object while (More(query_iterate)) { cat(Next(query_iterate), "\n") }
resulted in: <xml>Iter 3</xml> <xml>Iter 4</xml>
Now, iterating over the same query gives: 0b <xml>Iter 3</xml> 0b <xml>Iter 4</xml>
Did something change in the client/server protocol or did I introduce an error somewhere?
Ben
Hi Ben,
The client API code hasn’t changed since BaseX 8. Maybe you need to revise your code.
If you believe something wrong happens in the API, I’d still need some more information on what you believe has changed exactly?
Best, Christian
Ben Engbers Ben.Engbers@be-logical.nl schrieb am Mo., 3. Feb. 2020, 15:11:
Hi,
As far as I can remember when using early versions from my client-software, the main difference in output after sending \04 or \1F to the database, was that in the latter case the output was preceded with XDM Meta data.
# Full query_txt <- "for $i in 1 to 2 return <xml>Text { $i }</xml>" query_obj <- Query(Session, query_txt) result <- Full(query_obj)
resulted in: "0b" "<xml>Text 1</xml>" "0b" "<xml>Text 2</xml>"
# Iterate over query query2 <- "for $i in 3 to 4 return <xml>Iter { $i }</xml>" query_iterate <- Query(Session, query2) # <== Alternative call to query-object while (More(query_iterate)) { cat(Next(query_iterate), "\n") }
resulted in: <xml>Iter 3</xml> <xml>Iter 4</xml>
Now, iterating over the same query gives: 0b <xml>Iter 3</xml> 0b <xml>Iter 4</xml>
Did something change in the client/server protocol or did I introduce an error somewhere?
Ben
Op 04-02-2020 om 08:12 schreef Christian Grün:
Hi Ben,
The client API code hasn’t changed since BaseX 8. Maybe you need to revise your code.
If you believe something wrong happens in the API, I’d still need some more information on what you believe has changed exactly?
Best, Christian
Hi Christian, It shouldn't be too difficult to read this code:
More = function() { if (is.null(private$cache)) { # The cache has to be filled in_stream <- private$sock$get_socket() private$write_code_ID(0x04) cache <- c() while ((rd <- readBin(in_stream, what = "raw", n =1)) > 0) { cache <- c(cache, as.character(rd)) cache <- c(cache, private$sock$str_receive()) } success <- private$parent$get_socket()$bool_test_sock() private$parent$set_success(success) private$cache <- cache private$pos <- 0 } if ( length(private$cache) > private$pos) return(TRUE) else { private$cache <- NULL return(FALSE) }}
Next = function() { if (self$More()) { private$pos <- private$pos + 1 result <- private$cache[private$pos] } return(result)}
Full = function() { in_stream <- out_stream <- private$sock$get_socket() private$write_code_ID(0x1F) cache <- c() while ((rd <- readBin(in_stream, what = "raw", n =1)) > 0) { cache <- c(cache, as.character(rd)) cache <- c(cache, private$sock$str_receive()) } private$parent$get_socket()$bool_test_sock() result <- cache return(result) }
Both More() and Full() start by filling the cache. Next() is used by More() to iterate over the results. The main difference is the code that is sent to the database (0x04 versus 0x1F).
Query_1 <- Query(Session, "for $i in 1 to 2 return <xml>Text { $i }</xml>") fullResult <- Full(Query_1)
results in: "0b" "<xml>Text 1</xml>" "0b" "<xml>Text 2</xml>"
The result from: iterResult <- c() while (More(Query_1)) {iterResult <- c(iterResult, Next(Query_1))}
is identical but as far as I can remember, it should have been: "<xml>Text 1</xml>" "<xml>Text 2</xml>"
Can you tell if the results should be identical or different? If different, I'll have to install older versions from my code ;-(
Cheers, Ben
basex-talk@mailman.uni-konstanz.de