Anaristos

sqlServer (PublicInterface)

Dec 11th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.26 KB | None | 0 0
  1. /************************************************************************
  2. --[ License ] -----------------------------------------------------------
  3.  
  4.   This program is free software; you can redistribute it and/or
  5.   modify it under the terms of the GNU General Public License
  6.   as published by the Free Software Foundation; either version 3
  7.   of the License, or (at your option) any later version.
  8.  
  9.   This program is distributed in the hope that it will be useful,
  10.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.   GNU General Public License for more details.
  13.  
  14.   You should have received a copy of the GNU General Public License
  15.   along with this program; if not, write to the Free Software
  16.   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.    
  18.   You may also access the licence here: http://www.gnu.org/licenses/gpl.html
  19.  
  20.  ------------------------------------------------------------------------
  21.   Copyright © 2009-11 Gomez & Associates
  22. /************************************************************************/
  23.  
  24. using System;
  25. using System.Collections;
  26. using System.Collections.Generic;
  27. using System.Data;
  28. using System.Windows.Forms;
  29. using JSON;
  30.  
  31. namespace sqlServer
  32. {
  33.     public partial class DataProvider
  34.     {
  35.         public DataProvider()
  36.         {
  37.             this.init(null, false);
  38.         }
  39.  
  40.         public DataProvider(string dbName)
  41.         {
  42.             this.init(dbName, false);
  43.         }
  44.  
  45.         public DataProvider(string dbName, bool json)
  46.         {
  47.             this.init(dbName, json);
  48.         }
  49.  
  50.         public object exec(string input)
  51.         {
  52.             return execute(input);
  53.         }
  54.  
  55.         /// <summary>
  56.         /// Execute a request against the current database.
  57.         /// </summary>
  58.         /// <param name="input">
  59.         /// Item 1:      The procedure to be executed.
  60.         /// Item 2:      The commnand type (insert, delete, procedure or update).
  61.         /// Data Record: Contains key/value pairs representing named parameters.
  62.         ///              The key is the name of the parameter.
  63.         /// Note that "?" placeholders are not supported so all parameters are
  64.         /// named.
  65.         /// </param>
  66.         public object execute(string input)
  67.         {
  68.             if (input.Length > 0)
  69.             {
  70.                 ArrayList ur = (ArrayList) JSON.JSON.JsonDecode(input);
  71.  
  72.                 if (JSON.JSON.GeterrormsgIndex() != -1)
  73.                 {
  74.                     MessageBox.Show(JSON.JSON.GeterrormsgSnippet());
  75.  
  76.                     return null;
  77.                 }
  78.  
  79.                 if (ur.Count < 2 || ur.Count > 3)
  80.                 {
  81.                     _errormsg = "Invalid number of parameters.";
  82.  
  83.                     return null;
  84.                 }
  85.  
  86.                 string sql = (string) ur[0];
  87.  
  88.                 Int64 ureq = (Int64) ur[1];
  89.  
  90.                 int req;
  91.  
  92.                 Hashtable plist = ur.Count == 3 ? (Hashtable) ur[2] : null;
  93.  
  94.                 int.TryParse(ureq.ToString(), out req);
  95.  
  96.                 if ((reqType)req == reqType.None || (reqType)req >= reqType.BadReq)
  97.                 {
  98.                     _errormsg = "Invalid Request Type";
  99.  
  100.                     return null;
  101.                 }
  102.  
  103.                 execMethod method = (execMethod) methods[(reqType) req];
  104.  
  105.                 try
  106.                 {
  107.                     return method(sql, plist);
  108.                 }
  109.  
  110.                 catch (Exception e)
  111.                 {
  112.                     _errormsg = e.Message;
  113.  
  114.                     return null;
  115.                 }
  116.             }
  117.  
  118.             else
  119.             {
  120.                 _errormsg = "Invalid number of parameters.";
  121.  
  122.                 return null;
  123.             }
  124.         }
  125.  
  126.         public bool CMUDFormat
  127.         {
  128.             get { return _cmudFormat; }
  129.             set { _cmudFormat = value; }
  130.         }
  131.  
  132.         public string CurrConn
  133.         {
  134.             get { return _currConn; }
  135.             set { _currConn = value; }
  136.         }
  137.  
  138.         public string dbName
  139.         {
  140.             get { return _dbName; }
  141.             set { _dbName = value; }
  142.         }
  143.  
  144.         public bool Debug
  145.         {
  146.             get { return _debug; }
  147.             set { _debug = value; }
  148.         }
  149.  
  150.         public string DefaultInstance
  151.         {
  152.             get { return _defaultInstance; }
  153.             set { _defaultInstance = value; }
  154.         }
  155.  
  156.         public string ErrorMsg
  157.         {
  158.             get { return _errormsg; }
  159.         }
  160.  
  161.         public string HashEntrySep
  162.         {
  163.             get { return _hashEntrySep; }
  164.             set { _hashEntrySep = value; }
  165.         }
  166.  
  167.         public string Instance
  168.         {
  169.             get { return _instance; }
  170.             set { _instance = value; }
  171.         }
  172.  
  173.         public bool isOpen
  174.         {
  175.             get { return _open; }
  176.         }
  177.  
  178.         public bool JSONFormat
  179.         {
  180.             get { return _useJson; }
  181.             set { _useJson = value; }
  182.         }
  183.  
  184.         public string KeyValueSep
  185.         {
  186.             get { return _keyValueSep; }
  187.             set { _keyValueSep = value; }
  188.         }
  189.  
  190.         public string MachineName
  191.         {
  192.             get { return _machineName; }
  193.             set { _machineName = value; }
  194.         }
  195.  
  196.         public string Null
  197.         {
  198.             get { return _null; }
  199.             set { _null = value; }
  200.         }
  201.  
  202.         public string Provider
  203.         {
  204.             get { return _provider; }
  205.         }
  206.  
  207.         public string ResultSep
  208.         {
  209.             get { return _resultSep; }
  210.             set { _resultSep = value; }
  211.         }
  212.  
  213.         public bool UseMap
  214.         {
  215.             get { return _useMap; }
  216.             set { _useMap = value; }
  217.         }
  218.  
  219.         public string Version
  220.         {
  221.             get {
  222.                     if (_conn != null)
  223.                     {
  224.                         return this.GetType().Assembly.GetName().Version.ToString() + "/SQL Server Version (" + _conn.DataSource + "): " + _conn.ServerVersion;
  225.                     }
  226.                     else return this.GetType().Assembly.GetName().Version.ToString() + "/SQL Server Version: N/A";
  227.                 }
  228.         }
  229.     }
  230. }
  231.  
  232.  
Advertisement
Add Comment
Please, Sign In to add comment