INSERT Statement N1QL

Hello!

I am trying to run a simple insert n1ql statement but I am getting errors. I would appreciate if someone could help me out. I removed the code where the connection is created. If I run the insert statement from the web interface removing ‘’ character , it works. INSERT INTO tires-3dm ( KEY, VALUE ) VALUES (“tire_004”, {})

std::string sqlstmt = "INSERT INTO `tires-3dm` ( KEY, VALUE ) VALUES (\"tire_004\", {})";


// Initialize the queries:
lcb_CMDN1QL cmd = { 0 };

// Allocate the parameter object
lcb_N1QLPARAMS *nparams = lcb_n1p_new();
//rc = lcb_n1p_setstmtz(nparams, "select * from `tires-3dm` where plant=$param");
rc = lcb_n1p_setstmtz(nparams, sqlstmt.c_str());
if (rc != LCB_SUCCESS)
	return;

   lcb_n1p_mkcmd(nparams, &cmd);

   rc = lcb_n1ql_query(instance, NULL, &cmd);
   if (rc != LCB_SUCCESS)                                                             <=== getting error here
      return;

could you run your code with LCB_LOGLEVEL=5 environment variable, also check what the server returns to you in the callback (I hope you set the callback, but just omitted here for brevity, right?).

This is how, for example, cbc-n1ql command reports errors:

Thanks for your answer. I haven’t set the callback, do I have to? Sorry for my lack of knowledge but I started to play around with Couchbase 3 days ago. That said, from my point of view I just need a callback when the query is returning some data.

if you want to use query result, then, yes, you need to setup the callback.

You can find more query examples here: https://github.com/couchbaselabs/devguide-examples/tree/master/c
Like this for example:
https://github.com/couchbaselabs/devguide-examples/blob/master/c/query-criteria.cc#L50-L57