/// <summary> /// Creates new PDO DB connection. /// </summary> public override PDOConnection OpenConnection(ScriptContext context, string dsn_data, string username, string password, object argdriver_options) { ////Determine file path //string filename = dsn_data.Replace('/', Path.DirectorySeparatorChar); //string filePath = Path.GetFullPath(Path.Combine(context.WorkingDirectory, filename)); var csb = new MySqlConnectionStringBuilder(); SetupConnectionString(csb, dsn_data); csb.AllowUserVariables = true; csb.AllowZeroDateTime = true; if (username != null) { csb.UserID = username; } if (password != null) { csb.Password = password; } if (argdriver_options is PhpArray) { // TODO: process argdriver_options } var con = new PDOConnection(csb.GetConnectionString(true), new MySqlConnection(), "PDO mysql connection"); con.Connect(); return(con); }
public virtual object __construct(ScriptContext context, object argdsn, [Optional] object argusername, [Optional] object argpassword, [Optional] object argdriver_options) { string dsn = PHP.Core.Convert.ObjectToString(argdsn); string username = (argusername == Arg.Default) ? null : PHP.Core.Convert.ObjectToString(argusername); string password = (argpassword == Arg.Default) ? null : PHP.Core.Convert.ObjectToString(argpassword); object driver_options = (argdriver_options == Arg.Default) ? null : argdriver_options; if (string.IsNullOrEmpty(dsn)) { throw new ArgumentNullException(); } const string uri = "uri:"; if (dsn.StartsWith(uri)) { Uri url = new Uri(dsn.Substring(uri.Length)); throw new NotImplementedException("PDO uri handling"); } string[] items = dsn.Split(new char[] { ':' }, 2); if (items.Length == 1) { //TODO : try to search for aliasing throw new NotImplementedException("PDO DSN aliasing"); } if (items.Length == 2) { string drvName = items[0]; this.m_driver = PDOLibraryDescriptor.GetProvider(drvName); if (this.m_driver == null) { PDOException.Throw(context, "Driver not found", null, null, null); return(null); } this.m_con = this.m_driver.OpenConnection(context, items[1], username, password, driver_options); } if (this.m_driver == null || this.m_con == null) { PDOException.Throw(context, "Invalid DSN", null, null, null); return(null); } //Defaults this.SetAttributeValueNoCheck(ATTR_AUTOCOMMIT, true); this.SetAttributeValueNoCheck(ATTR_DEFAULT_FETCH_MODE, FETCH_BOTH); this.SetAttributeValueNoCheck(ATTR_DRIVER_NAME, this.m_driver.Scheme); this.SetAttributeValueNoCheck(ATTR_ORACLE_NULLS, NULL_NATURAL); this.SetAttributeValueNoCheck(ATTR_STRINGIFY_FETCHES, false); this.SetAttributeValueNoCheck(ATTR_TIMEOUT, 30000); return(null); }
public override PDOConnection OpenConnection(ScriptContext context, string dsn_data, string username, string password, object argdriver_options) { //Determine file path string filename = dsn_data.Replace('/', Path.DirectorySeparatorChar); string filePath = Path.GetFullPath(Path.Combine(context.WorkingDirectory, filename)); SQLiteConnectionStringBuilder csb = new SQLiteConnectionStringBuilder(); csb.DataSource = filePath; csb.Version = 3; var con = new PDOConnection(csb.ConnectionString, new SQLiteConnection(), "PDO sqllite connection"); con.Connect(); return con; }
public override PDOConnection OpenConnection(ScriptContext context, string dsn_data, string username, string password, object argdriver_options) { //Determine file path string filename = dsn_data.Replace('/', Path.DirectorySeparatorChar); string filePath = Path.GetFullPath(Path.Combine(context.WorkingDirectory, filename)); SQLiteConnectionStringBuilder csb = new SQLiteConnectionStringBuilder(); csb.DataSource = filePath; csb.Version = 3; var con = new PDOConnection(csb.ConnectionString, new SQLiteConnection(), "PDO sqllite connection"); con.Connect(); return(con); }
public object __construct(ScriptContext context, object argdsn, [Optional] object argusername, [Optional] object argpassword, [Optional] object argdriver_options) { string dsn = PHP.Core.Convert.ObjectToString(argdsn); string username = (argusername == Arg.Default) ? null : PHP.Core.Convert.ObjectToString(argusername); string password = (argpassword == Arg.Default) ? null : PHP.Core.Convert.ObjectToString(argpassword); object driver_options = (argdriver_options == Arg.Default) ? null : argdriver_options; if (string.IsNullOrEmpty(dsn)) throw new ArgumentNullException(); const string uri = "uri:"; if (dsn.StartsWith(uri)) { Uri url = new Uri(dsn.Substring(uri.Length)); throw new NotImplementedException("PDO uri handling"); } string[] items = dsn.Split(new char[] { ':' }, 2); if (items.Length == 1) { //TODO : try to search for aliasing throw new NotImplementedException("PDO DSN aliasing"); } if (items.Length == 2) { string drvName = items[0]; this.m_driver = PDOLibraryDescriptor.GetProvider(drvName); if (this.m_driver == null) { PDOException.Throw(context, "Driver not found", null, null, null); return null; } this.m_con = this.m_driver.OpenConnection(context, items[1], username, password, driver_options); } if (this.m_driver == null || this.m_con == null) { PDOException.Throw(context, "Invalid DSN", null, null, null); return null; } //Defaults this.SetAttributeValueNoCheck(ATTR_AUTOCOMMIT, true); this.SetAttributeValueNoCheck(ATTR_DEFAULT_FETCH_MODE, FETCH_BOTH); this.SetAttributeValueNoCheck(ATTR_DRIVER_NAME, this.m_driver.Scheme); this.SetAttributeValueNoCheck(ATTR_ORACLE_NULLS, NULL_NATURAL); this.SetAttributeValueNoCheck(ATTR_STRINGIFY_FETCHES, false); this.SetAttributeValueNoCheck(ATTR_TIMEOUT, 30000); return null; }
/// <summary> /// Creates new PDO DB connection. /// </summary> public override PDOConnection OpenConnection(ScriptContext context, string dsn_data, string username, string password, object argdriver_options) { ////Determine file path //string filename = dsn_data.Replace('/', Path.DirectorySeparatorChar); //string filePath = Path.GetFullPath(Path.Combine(context.WorkingDirectory, filename)); var csb = new MySqlConnectionStringBuilder(); SetupConnectionString(csb, dsn_data); csb.AllowUserVariables = true; csb.AllowZeroDateTime = true; if (username != null) csb.UserID = username; if (password != null) csb.Password = password; if (argdriver_options is PhpArray) { // TODO: process argdriver_options } var con = new PDOConnection(csb.GetConnectionString(true), new MySqlConnection(), "PDO mysql connection"); con.Connect(); return con; }