var _db = require("topsin.database");
var _error = require("topsin.error");

try {
  var DEMO_CONN = "DEMO_CONN";

  _db.addConnection({
    database_type: "mssql",
    database_host: "139.196.104.13",
    database_name: "DB_PCB_LDI_History_Report",
    database_user: "sa",
    database_pwd: "TopLinker0510"
  }, DEMO_CONN);
  
  var query = _db.query(DEMO_CONN);
  
  var sql = " \
    select base64 \
    from HistoryFiducials \
    cross apply (select Image as '*' for xml path('')) T (base64) \
    where ExposureFK = '12159' \
  ";
  
  var data = query.selectArrayMap(sql, {});
  if (query.lastError().isValid()) {
    throw query.lastError().text();
  }
  print(data.length);
  print("To Base64: ", JSON.stringify(data));

  sql = " \
    SELECT * \
    FROM HistoryFiducials WHERE ExposureFK = '12159' \
  ";
  data = query.selectArrayMap(sql, {});
  if (query.lastError().isValid()) {
    throw query.lastError().text();
  }
  print("Normal: ", JSON.stringify(data));
} catch (e) {
  print(e)
}
