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