Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************************************************
- --[ License ] -----------------------------------------------------------
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 3
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- You may also access the licence here: http://www.gnu.org/licenses/gpl.html
- ------------------------------------------------------------------------
- Copyright © 2009-11 Gomez & Associates
- /************************************************************************/
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Windows.Forms;
- using JSON;
- namespace sqlServer
- {
- public partial class DataProvider
- {
- public DataProvider()
- {
- this.init(null, false);
- }
- public DataProvider(string dbName)
- {
- this.init(dbName, false);
- }
- public DataProvider(string dbName, bool json)
- {
- this.init(dbName, json);
- }
- public object exec(string input)
- {
- return execute(input);
- }
- /// <summary>
- /// Execute a request against the current database.
- /// </summary>
- /// <param name="input">
- /// Item 1: The procedure to be executed.
- /// Item 2: The commnand type (insert, delete, procedure or update).
- /// Data Record: Contains key/value pairs representing named parameters.
- /// The key is the name of the parameter.
- /// Note that "?" placeholders are not supported so all parameters are
- /// named.
- /// </param>
- public object execute(string input)
- {
- if (input.Length > 0)
- {
- ArrayList ur = (ArrayList) JSON.JSON.JsonDecode(input);
- if (JSON.JSON.GeterrormsgIndex() != -1)
- {
- MessageBox.Show(JSON.JSON.GeterrormsgSnippet());
- return null;
- }
- if (ur.Count < 2 || ur.Count > 3)
- {
- _errormsg = "Invalid number of parameters.";
- return null;
- }
- string sql = (string) ur[0];
- Int64 ureq = (Int64) ur[1];
- int req;
- Hashtable plist = ur.Count == 3 ? (Hashtable) ur[2] : null;
- int.TryParse(ureq.ToString(), out req);
- if ((reqType)req == reqType.None || (reqType)req >= reqType.BadReq)
- {
- _errormsg = "Invalid Request Type";
- return null;
- }
- execMethod method = (execMethod) methods[(reqType) req];
- try
- {
- return method(sql, plist);
- }
- catch (Exception e)
- {
- _errormsg = e.Message;
- return null;
- }
- }
- else
- {
- _errormsg = "Invalid number of parameters.";
- return null;
- }
- }
- public bool CMUDFormat
- {
- get { return _cmudFormat; }
- set { _cmudFormat = value; }
- }
- public string CurrConn
- {
- get { return _currConn; }
- set { _currConn = value; }
- }
- public string dbName
- {
- get { return _dbName; }
- set { _dbName = value; }
- }
- public bool Debug
- {
- get { return _debug; }
- set { _debug = value; }
- }
- public string DefaultInstance
- {
- get { return _defaultInstance; }
- set { _defaultInstance = value; }
- }
- public string ErrorMsg
- {
- get { return _errormsg; }
- }
- public string HashEntrySep
- {
- get { return _hashEntrySep; }
- set { _hashEntrySep = value; }
- }
- public string Instance
- {
- get { return _instance; }
- set { _instance = value; }
- }
- public bool isOpen
- {
- get { return _open; }
- }
- public bool JSONFormat
- {
- get { return _useJson; }
- set { _useJson = value; }
- }
- public string KeyValueSep
- {
- get { return _keyValueSep; }
- set { _keyValueSep = value; }
- }
- public string MachineName
- {
- get { return _machineName; }
- set { _machineName = value; }
- }
- public string Null
- {
- get { return _null; }
- set { _null = value; }
- }
- public string Provider
- {
- get { return _provider; }
- }
- public string ResultSep
- {
- get { return _resultSep; }
- set { _resultSep = value; }
- }
- public bool UseMap
- {
- get { return _useMap; }
- set { _useMap = value; }
- }
- public string Version
- {
- get {
- if (_conn != null)
- {
- return this.GetType().Assembly.GetName().Version.ToString() + "/SQL Server Version (" + _conn.DataSource + "): " + _conn.ServerVersion;
- }
- else return this.GetType().Assembly.GetName().Version.ToString() + "/SQL Server Version: N/A";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment