
{
  "synLogic": "int $ret \u003d $api($1);",
  "help": "This API is used to execute the SQL statement which has been prepared by ns_db_prepare and ns_db_bindparameter api.\n Through this api, the SQL statement will be compiled only once and can be executed again and again hence minimizing the execution time required by the same-looking queries.",
  "notes": "ns_db_odbc_init, ns_db_connect, ns_db_alloc_stmt_handle, ns_db_prepare, ns_db_bindparameter APIs must be called in this sequence before calling this API",
  "returns": "This api returns '0' on success and '-1' on failure.",
  "arguments": "",
  "parameterization": "",
  "name": "ns_db_execute",
  "syntax": "int ns_db_execute(void *in_stmt)",
  "javaSyntax": "",
  "cEx": "extern int db_log_result(char *, char *); \n\nvoid db_select_flow() \n{ \n  char buf[2048]; \n  void *stmt \u003d NULL; \n\n  char tablename[30], qstr[256]; \n  sprintf(tablename, \"products_%04d%06d\", ns_get_nvmid(), ns_get_userid()); \n\n  // Initialize db environement and variables \n  if(ns_db_odbc_init() \u003d\u003d -1) \n  { \n    ns_db_odbc_close(); \n    return; \n  } \n\n  ns_start_transaction(\"Connect_db_for_select\"); \n\n  // Connect to database with DSN PostgresSQL, username netstorm and password test123 \n  if(ns_db_connect(\"DSN\u003dPostgreSQL; Username\u003dnetstorm; Datbase\u003dtest\") \u003d\u003d -1) \n  { \n    ns_set_tx_status(\"Connect_db_for_select\", 70); \n    ns_db_odbc_close(); \n    return; \n  } \n\n  ns_end_transaction(\"Connect_db_for_select\", NS_AUTO_STATUS); \n\n  // Allocate statement handle. \n  if(ns_db_alloc_stmt_handle(\u0026stmt) \u003d\u003d -1) \n  { \n    ns_db_odbc_close(); \n    return; \n  } \n\n  ns_start_transaction(\"Run_select\"); \n\n  sprintf(qstr, \"select * from %s;\", tablename); \n  // Executing select query \n  if(ns_db_execute(stmt, qstr) \u003d\u003d -1) \n  { \n    ns_set_tx_status(\"Run_select\", NS_TX_ERROR); \n    fprintf(stderr, \"Error in executing query: [%s]\\n\", qstr); \n  } \n\n  ns_end_transaction(\"Run_select\", NS_AUTO_STATUS); \n\n  ns_page_think_time(1); \n  if(ns_db_get_value(stmt, buf, 2048) \u003d\u003d -1) \n    fprintf(stderr, \"Error in executing query: [%s]\\n\", qstr); \n\n  printf(\"\\n\u003d\u003d\u003d\u003d\u003d\u003d\\nBuffer \u003d %s\\n\u003d\u003d\u003d\u003d\u003d\u003d\\n\", buf); \n  db_log_result(\"select\", buf); \n\n  ns_db_free_stmt(stmt); \n  ns_db_odbc_close(); \n} \n",
  "javaEx": "",
  "insertStrC": "ns_db_execute(void *in_stmt);",
  "insertStrJava": "",
  "description": "The ns_db_execute API is used to execute the SQL statement which has been prepared by ns_db_prepare() and ns_db_bindparameter(). \nThrough this api, the SQL statement will be compiled only once and can be executed repeatedly hence minimizing the execution time required by the same-looking queries.",
  "component":[
     {
      "id": "$1",
      "type": "TEXT_VAR",
      "label": "Statement",
      "labelVarCheckbox": "If statement is a program variable.",
      "value": "",
      "css": "p-grid p-align-center w-100-p",
      "title": "Enter statement",
      "placeHolder": "",
      "style": "",
      "isDisabled": "",
      "validate": {
        "inputType": "Text",
        "required": true
      }
    },
    {
      "id": "$ret",
      "type": "TextField",
      "label": "Return Value",
      "value": "",
      "css": "p-grid p-align-center w-100-p",
      "title": "Enter Return Value",
      "placeHolder": "",
      "style": "",
      "isDisabled": "",
      "labelVarCheckbox": "",
      "argIndex": 0,
      "validate": {
        "inputType": "Text",
        "disabled": false,
        "required": false,
        "method": "isValidVar(arg)"
      }
    }
  ]
}
