public WebDataTable TableQuery(WebSqlCommand sqlCmd) { if (!sqlCmd.SqlQuery.StartsWith("SELECT", StringComparison.CurrentCultureIgnoreCase)) { throw new WebDatabaseException("Only SELECT query is supported in WebDatabase TableQuery function."); } if (_inTransaction) { throw new WebDatabaseException("SELECT query not supported while WebDatabase is in a transaction."); } byte[] buffer; try { _webClient.QueryString.Clear(); buffer = _webClient.UploadValues(_webDatabaseUri, "POST", GetPostValues(sqlCmd)); } catch (Exception ex) { throw new WebDatabaseException(ex.Message, ex, -1); } using (BinaryReader bR = new BinaryReader(new MemoryStream(buffer))) { int errorCode = bR.ReadInt32(); if (errorCode != 0) { string message = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadInt32())); string remoteStackTrace = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadInt32())); throw new WebDatabaseException(message, errorCode, remoteStackTrace); } WebDataTable DT = new WebDataTable(); #region read column names byte colCount = bR.ReadByte(); for (int col = 0; col < colCount; col++) { DT.Columns.Add(Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()))); } #endregion #region read row data int rowCount = bR.ReadInt32(); for (int row = 0; row < rowCount; row++) { WebDataRow DR = new WebDataRow(DT); for (int col = 0; col < colCount; col++) { DR.Items.Add(new WebDbDataItem(bR.BaseStream)); } DT.Rows.Add(DR); } #endregion return(DT); } }
public WebDataRow(WebDataTable DT) { _columns = DT.Columns; }