OmniSciDB  c07336695a
MapDExample.MapDExample Class Reference

Static Public Member Functions

static void Main ()
 
static MapD.Client get_client (string host_or_uri, int port, bool http)
 

Detailed Description

Definition at line 29 of file MapDExample.cs.

Member Function Documentation

◆ get_client()

static MapD.Client MapDExample.MapDExample.get_client ( string  host_or_uri,
int  port,
bool  http 
)
inlinestatic

Definition at line 103 of file MapDExample.cs.

References client.

103  {
104  THttpClient httpTransport;
105  TTransport transport;
106  TBinaryProtocol protocol;
107  TJSONProtocol jsonProtocol;
108  MapD.Client client;
109 
110  try {
111  if (http) {
112  Uri httpuri = new Uri(host_or_uri);
113  httpTransport = new THttpClient(httpuri);
114  jsonProtocol = new TJSONProtocol(httpTransport);
115  client = new MapD.Client(jsonProtocol);
116  httpTransport.Open();
117  return client;
118  } else {
119  transport = new TSocket(host_or_uri, port);
120  protocol = new TBinaryProtocol(transport);
121  client = new MapD.Client(protocol);
122  transport.Open();
123  return client;
124  }
125  } catch (TException x) {
126  Console.WriteLine(x.StackTrace);
127  }
128  return null;
129  }
mapd::shared_ptr< MapDClient > client

◆ Main()

static void MapDExample.MapDExample.Main ( )
inlinestatic

Definition at line 31 of file MapDExample.cs.

References anonymous_namespace{ExecuteTest.cpp}.c(), client, MapDExample.get_client(), anonymous_namespace{UpdateMetadataTest.cpp}.query, and session.

31  {
32  string db_name = "omnisci";
33  string user_name = "admin";
34  string passwd = "HyperInteractive";
35  string hostname = "http://test.mapd.com";
36  int portno = 6274;
37  MapD.Client client;
38  int session;
39  string query;
40  TQueryResult results;
41  int numRows, numCols;
42  bool fieldIsArray;
43  TDatumType fieldType;
44  string fieldName, fieldType2;
45  try {
46  client = get_client(hostname, portno, true);
47  session = client.connect(user_name, passwd, db_name);
48  Console.WriteLine("Connection Completed");
49  query = "select a, b from table1 limit 10;";
50  Console.WriteLine("Query is: " + query);
51  results = client.sql_execute(session, query, true, null, -1, -1);
52 
53  if (results.Row_set.Is_columnar) {
54  numRows = results.Row_set.Columns[0].Nulls.Count;
55  numCols = results.Row_set.Row_desc.Count;
56  for (int r = 0; r < numRows; r++) {
57  for (int c = 0; c < numCols; c++) {
58  fieldName = results.Row_set.Row_desc[c].Col_name;
59  fieldType = results.Row_set.Row_desc[c].Col_type.Type;
60  fieldType2 = fieldType.ToString();
61  fieldIsArray = results.Row_set.Row_desc[c].Col_type.Is_array;
62  Console.WriteLine(fieldName);
63  if (fieldIsArray) {
64  Console.WriteLine(results.Row_set.Columns[c].Data.Arr_col[r].Data.Str_col);
65  } else {
66  switch (fieldType2) {
67  case "BOOL":
68  break;
69  case "SMALLINT":
70  case "INT":
71  case "BIGINT":
72  Console.WriteLine(results.Row_set.Columns[c].Data.Int_col[r]);
73  break;
74  case "FLOAT":
75  case "DOUBLE":
76  case "DECIMAL":
77  Console.WriteLine(results.Row_set.Columns[c].Data.Real_col[r]);
78  break;
79  case "STR":
80  Console.WriteLine(results.Row_set.Columns[c].Data.Str_col[r]);
81  break;
82  case "TIME":
83  case "TIMESTAMP":
84  case "DATE":
85  Console.WriteLine(
86  new DateTime(1970, 1, 1, 0, 0, 0)
87  .AddMilliseconds(Convert.ToDouble(
88  results.Row_set.Columns[c].Data.Int_col[r] * 1000)));
89  break;
90  default:
91  break;
92  }
93  }
94  }
95  }
96  }
97  } catch (TApplicationException x) {
98  Console.WriteLine(x.StackTrace);
99  }
100  }
void c(const std::string &query_string, const ExecutorDeviceType device_type)
static MapD.Client get_client(string host_or_uri, int port, bool http)
Definition: MapDExample.cs:103
mapd::shared_ptr< MapDClient > client
TSessionId session
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: