Exemple #1
0
// Run a prepared query.
func (query *Query) Run() (*Docs, error) {
	docs := &Docs{}
	query.lock.Lock()
	defer query.lock.Unlock()

	if !query.opened {
		return docs, errqueryclosed
	}
	docs.docs = C.c_dbxml_run_query(query.query)
	if C.c_dbxml_get_query_error(docs.docs) != 0 {
		defer C.c_dbxml_docs_free(docs.docs)
		return docs, errors.New(C.GoString(C.c_dbxml_get_query_errstring(docs.docs)))
	}
	runtime.SetFinalizer(docs, (*Docs).Close)
	docs.opened = true
	return docs, nil
}
Exemple #2
0
// Iterate to the next xml document in the list, that was returned by db.All(), db.Query(query), or query.Run().
func (docs *Docs) Next() bool {
	docs.lock.Lock()
	defer docs.lock.Unlock()
	if !docs.opened {
		return false
	}
	docs.err = nil
	if C.c_dbxml_docs_next(docs.docs) == 0 {
		if C.c_dbxml_get_query_error(docs.docs) != 0 {
			docs.err = errors.New(C.GoString(C.c_dbxml_get_query_errstring(docs.docs)))
		}
		docs.close()
		docs.started = false
		return false
	}
	docs.started = true
	return true
}