CHARP client.tcl - pupitetris/charp GitHub Wiki

A CHARP client written in TCL for testing and as an example for coding routines in TCL for a CHARP client. The program is not as verbose as client.pl for error reporting, but it gives the same information on the results.

Table of Contents

Usage

Same as client.pl:

$ ./client.tcl ''baseurl'' ''username'' ''password'' ''remote_procedure'' ''parameters''

Parameters

  • ''baseurl'' - The URL where the request and reply CGI scripts for the CHARP RPC can be found.
  • ''username'' - The login name for an existing account in the database.
  • ''password'' - The clear-text password for the account.
  • ''remote_procedure - The name of the remote procedure that will be called inside the database.
  • ''parameters'' - JSON-encoded array of parameters for the remote procedure. These must be enclosed in brackets.

Output

If the CHARP transaction completes, it shows the JSON code as it came from the server. This may be carrying resulting response data or a JSON-encapsulated error message.

Examples

A successful authentication call:

 $ ./client.tcl testuser blah user_auth '[]'
 {"fields":["success"],"data":[[1]]}

The same remote procedure, but with a non-existent account.

 $ ./client.tcl unkuser blah user_auth '[]'
 Error reportado en request
 {"error":{"msg":"CONTEXT:  SQL statement \"SELECT charp_raise('USERUNK', _username::text, _status::text)\"\nPL/pgSQL function
 \"charp_account_get_id_by_username_status\" line 7 at PERFORM\nSQL statement \"INSERT INTO request VALUES(\n_random_bytes,\ncharp_account_get_id_by_username_status(_username, 'ACTIVE'),\nCURRENT_TIMESTAMP,\n_ip_addr,\ncharp_rp_get_function_by_name(_function_name),\n_params\n)\"\nPL/pgSQL function \"charp_request_create\" line 5 at SQL statement","level":2,"sev":4,"desc":"
 Usuario `unkuser` con status `ACTIVE` no encontrado.","code":5,"key":"SQL:USERUNK"}}

Here we fetch the 32 states of Mexico:

 $ ./client.tcl testuser blah get_states '["Mexico",32]'
 {"fields":["state_id","circu_id","name","name_long","abrev","code_ife"],"data":[[1,2,"Aguascalientes","Aguascalientes","Ags",1],[2,1,"Baja California","Baja California","BC",2],[3,1,"Baja California Sur","Baja California Sur","BCS",3],[4,3,"Campeche","Campeche","Camp",4],[5,2,"Coahuila","Coahuila de Zaragoza","Coah",5],[6,5,"Colima","Colima","Col",6],[7,3,"Chiapas","Chiapas","Chis",7],[8,1,"Chihuahua","Chihuahua","Chih",8],[9,4,"Distrito Federal","Distrito Federal","DF",9],[10,1,"Durango","Durango","Dgo",10],[11,2,"Guanajuato","Guanajuato","Gto",11],[12,4,"Guerrero","Guerrero","Gro",12],[13,5,"Hidalgo","Hidalgo","Hgo",13],[14,1,"Jalisco","Jalisco","Jal",14],[15,5,"México","México","Mex",15],[16,5,"Michoacán","Michoacán de Ocampo","Mich",16],[17,4,"Morelos","Morelos","Mor",17],[18,1,"Nayarit","Nayarit","Nay",18],[19,2,"Nuevo León","Nuevo León","NL",19],[20,3,"Oaxaca","Oaxaca","Oax",20],[21,4,"Puebla","Puebla","Pue",21],[22,2,"Querétaro","Querétaro","Qro",22],[23,3,"Quintana Roo","Quintana Roo","QRoo",23],[24,2,"San Luis Potosí","San Luis Potosí","SLP",24],[25,1,"Sinaloa","Sinaloa","Sin",25],[26,1,"Sonora","Sonora","Son",26],[27,3,"Tabasco","Tabasco","Tab",27],[28,2,"Tamaulipas","Tamaulipas","Tam",28],[29,4,"Tlaxcala","Tlaxcala","Tlx",29],[30,3,"Veracruz","Veracruz de Ignacio de la Llave","Ver",30],[31,3,"Yucatán","Yucatán","Yuc",31],[32,2,"Zacatecas","Zacatecas","Zac",32]]}
⚠️ **GitHub.com Fallback** ⚠️