{"id":11224,"date":"2021-06-07T00:00:20","date_gmt":"2021-06-07T07:00:20","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=11224"},"modified":"2025-06-13T21:48:27","modified_gmt":"2025-06-14T04:48:27","slug":"using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/pt\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/","title":{"rendered":"Uso da libcouchbase \/ C SDK para executar transa\u00e7\u00f5es com o Couchbase 7.0"},"content":{"rendered":"<p><span style=\"font-weight: 400;\"><strong>O Couchbase Server 7.0 agora oferece suporte a transa\u00e7\u00f5es N1QL.<\/strong> <\/span><\/p>\r\n<p><span style=\"font-weight: 400;\">Vamos tentar escrever um programa em C que execute um conjunto de transa\u00e7\u00f5es em um \u00fanico n\u00f3.<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\"><strong>Etapa 1:<\/strong> Primeiro decidimos como chamar o programa. As entradas ser\u00e3o o URL do bucket do Couchbase no qual queremos executar as consultas e as credenciais (nome de usu\u00e1rio seguido da senha).\u00a0<\/span><\/p>\r\n\r\nUso: \r\n<pre>\r\n.\/n1ql couchbase:\/\/localhost\/test Administrator password\r\n<\/pre><br \/>\r\n\r\n<p><span style=\"font-weight: 400;\">Nas transa\u00e7\u00f5es N1QL, um valor txid \u00e9 retornado pelo comando START TRANSACTION. Esse valor \u00e9 usado em todas as consultas N1QL subsequentes dentro da transa\u00e7\u00e3o at\u00e9 o COMMIT ou ROLLBACK final. Portanto, devemos declarar um ID de transa\u00e7\u00e3o na fun\u00e7\u00e3o principal, que pode ser passado para as solicita\u00e7\u00f5es de consulta restantes que fazem parte da transa\u00e7\u00e3o.\u00a0<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\"><strong>Etapa 2:<\/strong> Inicializa um ponteiro que ser\u00e1 usado para salvar o ID da transa\u00e7\u00e3o da consulta BEGIN TRANSACTION. Esse ID ser\u00e1 usado em toda a transa\u00e7\u00e3o.<\/span><\/p>\r\n\r\n\r\n<pre>\r\nchar *transaction_id = (char *)malloc(64 * sizeof(char));\r\n<\/pre><br \/>\r\n\r\n\r\n<p><span style=\"font-weight: 400;\"><strong>Etapa 3:<\/strong> Inicializar o cluster\u00a0<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\">Uma conex\u00e3o com um cluster do Couchbase Server \u00e9 representada por um <\/span><span style=\"font-weight: 400;\">lcb_INSTANCE<\/span><span style=\"font-weight: 400;\"> objeto.<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\">lcb_INSTANCE *instance;<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\">O conjunto de opera\u00e7\u00f5es permitidas depende do tipo desse objeto e se o bucket est\u00e1 associado a ele. Aqui, usamos o tipo Cluster. <\/span><span style=\"font-weight: 400;\">A maneira mais simples de criar um objeto de cluster \u00e9 chamar <\/span><span style=\"font-weight: 400;\">lcb_create<\/span><span style=\"font-weight: 400;\"> para criar um identificador do Couchbase, passando <\/span><span style=\"font-weight: 400;\">LCB_TYPE_CLUSTER<\/span><span style=\"font-weight: 400;\"> com uma string de conex\u00e3o, nome de usu\u00e1rio e senha. Em seguida, programamos uma conex\u00e3o usando lcb_connect() e verificamos se o bucket existe.\u00a0<\/span><\/p>\r\n\r\n<pre>\r\nlcb_CREATEOPTS *create_options = NULL;\r\nlcb_createopts_create(&create_options, LCB_TYPE_CLUSTER);\r\nlcb_createopts_connstr(create_options, argv[1], strlen(argv[1]));\r\nlcb_createopts_credentials(create_options, argv[2], strlen(argv[2]), argv[3], strlen(argv[3]));\r\ncheck(lcb_create(&instance, create_options), \"create couchbase handle\");\r\nlcb_createopts_destroy(create_options);\r\ncheck(lcb_connect(instance), \"schedule connection\");\r\nlcb_wait(instance, LCB_WAIT_DEFAULT);\r\ncheck(lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_BUCKETNAME, &bucket), \"get bucket name\"); \r\n<\/pre><br \/>\r\n\r\n<p><span style=\"font-weight: 400;\"><strong>Etapa 4:<\/strong> Execute as consultas em query.h<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\">Temos as consultas correspondentes \u00e0 nossa transa\u00e7\u00e3o definidas em queries.h.\u00a0<\/span><\/p>\r\n\r\n<pre>\r\nBEGIN WORK\r\nINSERT INTO test VALUES(\\\"kkk1\\\", {\\\"a\\\":1})\r\nSELECT d.*, META(d).id FROM test AS d WHERE d.a &gt;= 0\r\nSAVEPOINT s1\r\nUPDATE test AS d SET d.b = 10 WHERE d.a &gt; 0\r\nSELECT d.*, META(d).id FROM test AS d WHERE d.a &gt;= 0\r\nSAVEPOINT s2\r\nUPDATE test AS d SET d.b = 10, d.c = \\\"xyz\\\" WHERE d.a &gt; 0\r\nSELECT d.*, META(d).id FROM test AS d WHERE d.a &gt;= 0\r\nROLLBACK TRAN TO SAVEPOINT s2\r\nSELECT d.*, META(d).id FROM test AS d WHERE d.a &gt;= 0\r\nINSERT INTO test VALUES(\\\"kkk2\\\", {\\\"a\\\":2})\r\nUPDATE test AS d SET d.b = 20, d.c = \\\"xyz\\\" WHERE d.a &gt; 0\r\nCOMMIT WORK\r\n<\/pre><br \/>\r\n\r\n<p><span style=\"font-weight: 400;\">Precisamos usar uma biblioteca de an\u00e1lise de JSON em C para tratar os resultados da consulta e extrair o ID da transa\u00e7\u00e3o. Aqui podemos usar a biblioteca json-c. Para obter o ID da transa\u00e7\u00e3o da instru\u00e7\u00e3o BEGIN WORK (a primeira instru\u00e7\u00e3o), usamos a fun\u00e7\u00e3o de retorno de chamada txid. Para processar e executar as outras consultas, chamamos a fun\u00e7\u00e3o de retorno de chamada de linha. Isso retornar\u00e1 as linhas de resultado.\u00a0<\/span><\/p>\r\n\r\n<pre>\r\nfor> (ii = >0>; ii &lt; num_queries; ii++) {>\r\n        >lcb_CMDQUERY> *>cmd>;      >\r\n        >lcb_cmdquery_create>(&cmd);>\r\n        >check>(lcb_cmdquery_statement(cmd, queries[ii].query, strlen(queries[ii].query)), >\"set QUERY statement\">);>\r\n        >printf>(>\"----&gt; \\x1b[1m%s\\x1b[0m\\n\">, queries[ii].query);>\r\n        >if> (ii == >0>) {>\r\n            >lcb_cmdquery_callback>(cmd, txid_callback);>\r\n            >lcb_wait>(instance, LCB_WAIT_DEFAULT);>\r\n            >check>(lcb_query(instance, transaction_id, cmd), >\"schedule QUERY operation\">);>\r\n            >lcb_wait>(instance, LCB_WAIT_DEFAULT);      >\r\n      } >else> {>\r\n            >char> buf>[100];>\r\n            >sprintf>(buf,>\"\\\">%s\\>\"\">,transaction_id);>\r\n            >lcb_cmdquery_callback>(cmd, row_callback);>\r\n\r\n          >\/\/ SET rest option pretty to true and txtimeout to 3s>\r\n            >check>(lcb_cmdquery_option(cmd, >\"pretty\">, strlen(>\"pretty\">), >\"true\">, strlen(>\"true\">)),>\"set QUERY 'pretty' option\">);>\r\n            >check>(lcb_cmdquery_option(cmd, >\"txtimeout\">, strlen(>\"txtimeout\">), >\"\\\">3s>\\>\"\">, strlen(>\"\\\">3s>\\>\"\">)),>\"set QUERY 'txtimeout' option\">);>\r\n            check(lcb_cmdquery_option(cmd, >\"txid\">, >strlen>(>\"txid\">),buf, >strlen>(buf)),>\"set QUERY 'txtimeout' option\">);>\r\n            check(lcb_query(instance, >NULL>, cmd), >\"schedule QUERY operation\">);>\r\n            lcb_wait(instance, LCB_WAIT_DEFAULT);>\r\n      }      >\r\n        lcb_cmdquery_destroy(cmd);>\r\n        lcb_wait(instance, LCB_WAIT_DEFAULT);>\r\n    }>\r\n<\/pre><br \/>\r\n\r\n<p><span style=\"font-weight: 400;\">Antes de executar as consultas, definimos tr\u00eas par\u00e2metros de consulta: pretty, txtimeout (tempo limite da transa\u00e7\u00e3o) e o txid que obtivemos na primeira instru\u00e7\u00e3o. Esses s\u00e3o par\u00e2metros em n\u00edvel de solicita\u00e7\u00e3o.\u00a0<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\">Agora vamos nos aprofundar nas fun\u00e7\u00f5es de retorno de chamada\u00a0<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\">Txid_Callback -\u00a0<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\">Aqui precisamos analisar a resposta JSON da execu\u00e7\u00e3o da instru\u00e7\u00e3o BEGIN WORK para extrair o txid a ser passado para as instru\u00e7\u00f5es subsequentes como um par\u00e2metro de consulta usando a biblioteca JSONC. Para isso, usamos o ponteiro criado anteriormente e o definimos no m\u00e9todo lcb_respquery_cookie. Isso define o cookie da opera\u00e7\u00e3o, o que significa que quando executamos lcb_query, h\u00e1 um argumento de cookie para ele e lcb_respquery_cookie obt\u00e9m esse ponteiro em nossa fun\u00e7\u00e3o de retorno de chamada. (Criamos um ponteiro na fun\u00e7\u00e3o principal e o definimos na fun\u00e7\u00e3o de retorno de chamada).<\/span><\/p>\r\n\r\n<pre>\r\n\/* create pointer transaction_id and set it in the callback  *\/\r\n  lcb_respquery_cookie(resp, (void **)&transaction_id);\r\n  check(lcb_respquery_status(resp),\"check response status\");\r\n  lcb_respquery_row(resp, &row, &nrow);\r\n  if (!lcb_respquery_is_final(resp)) {\r\n        parsed_json = json_tokener_parse(row);\r\n        json_object_object_get_ex(parsed_json, \"txid\", &txid_obj);\r\n        temp = json_object_get_string(txid_obj);\r\n        strcpy(transaction_id,temp);\r\n    }\r\n<\/pre><br \/>\r\n\r\n<p><span style=\"font-weight: 400;\">Callback de linha - \u00c9 usado para analisar e recuperar as linhas de resultado da execu\u00e7\u00e3o da consulta.\u00a0<\/span><\/p>\r\n\r\n<pre>\r\n    lcb_STATUS rc = lcb_respquery_status(resp);\r\n    lcb_respquery_row(resp, &row, &nrow);\r\n    ln2space(row, nrow);\r\n    fprintf(stderr, \"[\\x1b[%dmQUERY\\x1b[0m] %s, (%d) %.*s\\n\", err2color(rc), lcb_strerror_short(rc), (int)nrow,\r\n            (int)nrow, row);\r\n    if (lcb_respquery_is_final(resp)) {\r\n        fprintf(stderr, \"\\n\");\r\n    }\r\n}\r\n<\/pre><br \/>\r\n\r\n<p><span style=\"font-weight: 400;\">Aqui, obtemos a resposta da consulta, obtemos as linhas e as imprimimos.\u00a0<\/span><\/p>\r\n<p><span style=\"font-weight: 400;\">Usando o exemplo acima, agora podemos usar as transa\u00e7\u00f5es N1QL no C SDK. Para obter o c\u00f3digo completo e instru\u00e7\u00f5es sobre como execut\u00e1-lo, consulte - <\/span><a href=\"https:\/\/github.com\/ikandaswamy\/CBSDK_N1QLExamples\"><span style=\"font-weight: 400;\">https:\/\/github.com\/ikandaswamy\/CBSDK_N1QLExamples<\/span><\/a><\/p>\r\n\r\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Couchbase Server 7.0 now supports N1QL transactions. Let&#8217;s try writing a C program that performs a set of transactions on a single node. Step 1: We first decide how to call the program. The inputs will be the URL to [&hellip;]<\/p>","protected":false},"author":6882,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[9986,1812,2201,2396],"tags":[],"ppma_author":[9057],"class_list":["post-11224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c","category-n1ql-query","category-tools-sdks","category-transactions"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.2 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0 - The Couchbase Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/pt\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0\" \/>\n<meta property=\"og:description\" content=\"Couchbase Server 7.0 now supports N1QL transactions. Let&#8217;s try writing a C program that performs a set of transactions on a single node. Step 1: We first decide how to call the program. The inputs will be the URL to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/pt\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-07T07:00:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:48:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1800\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Isha Kandaswamy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Isha Kandaswamy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/\"},\"author\":{\"name\":\"Isha Kandaswamy\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f236f76f209f447fbc8fd46d91eb7e52\"},\"headline\":\"Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0\",\"datePublished\":\"2021-06-07T07:00:20+00:00\",\"dateModified\":\"2025-06-14T04:48:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/\"},\"wordCount\":534,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"articleSection\":[\"C\/C++\",\"SQL++ \/ N1QL Query\",\"Tools &amp; SDKs\",\"Transactions\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/\",\"name\":\"Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0 - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2021-06-07T07:00:20+00:00\",\"dateModified\":\"2025-06-14T04:48:27+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f236f76f209f447fbc8fd46d91eb7e52\",\"name\":\"Isha Kandaswamy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/e8464106b598ad96e4e1446687ce93f6\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g\",\"caption\":\"Isha Kandaswamy\"},\"description\":\"Isha Kandaswamy is a Senior Software Engineer at Couchbase. Isha is responsible for the development of designing the different features and tools for the N1QL Query Language -SQL for Json. Also, Designing and implementing features and tools for the N1QL query language.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/pt\/author\/isha-kandaswamy\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0 - The Couchbase Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/pt\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/","og_locale":"pt_BR","og_type":"article","og_title":"Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0","og_description":"Couchbase Server 7.0 now supports N1QL transactions. Let&#8217;s try writing a C program that performs a set of transactions on a single node. Step 1: We first decide how to call the program. The inputs will be the URL to [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/pt\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/","og_site_name":"The Couchbase Blog","article_published_time":"2021-06-07T07:00:20+00:00","article_modified_time":"2025-06-14T04:48:27+00:00","og_image":[{"width":1800,"height":630,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","type":"image\/png"}],"author":"Isha Kandaswamy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Isha Kandaswamy","Est. reading time":"4 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/"},"author":{"name":"Isha Kandaswamy","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f236f76f209f447fbc8fd46d91eb7e52"},"headline":"Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0","datePublished":"2021-06-07T07:00:20+00:00","dateModified":"2025-06-14T04:48:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/"},"wordCount":534,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","articleSection":["C\/C++","SQL++ \/ N1QL Query","Tools &amp; SDKs","Transactions"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/","url":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/","name":"Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0 - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2021-06-07T07:00:20+00:00","dateModified":"2025-06-14T04:48:27+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/using-libcouchbase-c-sdk-to-run-transactions-with-couchbase-7-0\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using libcouchbase \/ C SDK to run transactions with Couchbase 7.0"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"Blog do Couchbase","description":"Couchbase, o banco de dados NoSQL","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"Blog do Couchbase","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f236f76f209f447fbc8fd46d91eb7e52","name":"Isha Kandaswamy","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/e8464106b598ad96e4e1446687ce93f6","url":"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g","caption":"Isha Kandaswamy"},"description":"Isha Kandaswamy \u00e9 engenheira de software s\u00eanior da Couchbase. Isha \u00e9 respons\u00e1vel pelo desenvolvimento de diferentes recursos e ferramentas para a linguagem de consulta N1QL -SQL para Json. Al\u00e9m disso, projetar e implementar recursos e ferramentas para a linguagem de consulta N1QL.","url":"https:\/\/www.couchbase.com\/blog\/pt\/author\/isha-kandaswamy\/"}]}},"authors":[{"term_id":9057,"user_id":6882,"is_guest":0,"slug":"isha-kandaswamy","display_name":"Isha Kandaswamy","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g","author_category":"","last_name":"Kandaswamy","first_name":"Isha","job_title":"","user_url":"","description":"Isha Kandaswamy \u00e9 engenheira de software s\u00eanior da Couchbase. Isha \u00e9 respons\u00e1vel pelo desenvolvimento de diferentes recursos e ferramentas para a linguagem de consulta N1QL -SQL para Json. Al\u00e9m disso, projetar e implementar recursos e ferramentas para a linguagem de consulta N1QL."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/11224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/users\/6882"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/comments?post=11224"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/11224\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media?parent=11224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/categories?post=11224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/tags?post=11224"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/ppma_author?post=11224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}