Exemplo n.º 1
0
        private string ExecuteQuery(QueryParam queryParam)
        {
            TableItem tabItem = TableSet.GetImpl().GetTableInfo(queryParam.GetTableName());

            if (tabItem == null)
            {
                throw new Exception("table not found");
            }

            string querySql = queryParam.GetSql(tabItem);

            if (string.IsNullOrEmpty(querySql))
            {
                throw new Exception("invalid query param");
            }

            string        errMsg      = string.Empty;
            DataTable     resultTable = null;
            PDBConnection conn        = ConnectionPoolSet.GetImpl().GetConnection(tabItem.ServerName);

            try
            {
                PDBCommand cmd = conn.CreateCommand();
                resultTable = cmd.ExecuteQuery(querySql);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }

            ConnectionPoolSet.GetImpl().BackConnection(tabItem.ServerName, conn, errMsg != string.Empty);
            if (errMsg != string.Empty)
            {
                throw new Exception(errMsg);
            }

            JsonConverter[] pinusConverter = { new DateTime2LongConverter(), new BlobConverter() };
            return("{ \"err\":0, \"data\": " + JsonConvert.SerializeObject(resultTable, pinusConverter) + "}");
        }