Skip to content
Permalink
Browse files

Added draft of SQLite extension and PDO/PDOSQLite extension

Warning : System.Data.SQLite.dll is a customized one : for SQLite UDF usage in Phalanger
  • Loading branch information...
MaitreDede committed Jun 1, 2012
1 parent e783573 commit 6c73ad33f4d15d287f86c19359312a1944546c1a
Showing with 8,029 additions and 517 deletions.
  1. +27 −0 Source/Core/ApplicationContext.cs
  2. +9 −8 Source/Extensions/PDO/Extension.PDO.csproj
  3. +189 −12 Source/Extensions/PDO/PDO.cs
  4. +18 −0 Source/Extensions/PDO/PDOCaseConversion.cs
  5. +165 −165 Source/Extensions/PDO/PDOConnection.cs
  6. +16 −0 Source/Extensions/PDO/PDOCursorType.cs
  7. +17 −2 Source/Extensions/PDO/PDODriver.cs
  8. +18 −0 Source/Extensions/PDO/PDOErrorMode.cs
  9. +18 −0 Source/Extensions/PDO/PDONullHandling.cs
  10. +41 −0 Source/Extensions/PDO/PDOParamType.cs
  11. +60 −0 Source/Extensions/PDO/PDOStatement.PHP.cs
  12. +470 −112 Source/Extensions/PDO/PDOStatement.cs
  13. +0 −21 Source/Extensions/PDO/PDOStatics.pdo_case_conversion.cs
  14. +0 −19 Source/Extensions/PDO/PDOStatics.pdo_cursor_type.cs
  15. +0 −21 Source/Extensions/PDO/PDOStatics.pdo_error_mode .cs
  16. +0 −21 Source/Extensions/PDO/PDOStatics.pdo_null_handling.cs
  17. +0 −44 Source/Extensions/PDO/PDOStatics.pdo_param_type.cs
  18. +7 −0 Source/Extensions/PDOSQLite/Extension.PDOSQLite.csproj
  19. +6 −0 Source/Extensions/PDOSQLite/PDOSQLiteLibraryDescriptor.cs
  20. +53 −51 Source/Extensions/PDOSQLite/SQLitePDOConnection.cs
  21. +49 −3 Source/Extensions/PDOSQLite/SQLitePDODriver.cs
  22. +57 −0 Source/Extensions/PDOSQLite/SQLitePDOStatement.cs
  23. +11 −11 Source/Extensions/SQLite/Extension.SQLite.csproj
  24. +21 −1 Source/Extensions/SQLite/SQLite.cs
  25. +65 −26 Source/Extensions/SQLite/SQLiteDatabase.cs
  26. BIN Source/Extensions/SQLite/lib/SQLite.Designer.dll
  27. BIN Source/Extensions/SQLite/lib/SQLite.Designer.pdb
  28. BIN Source/Extensions/SQLite/lib/System.Data.SQLite.Linq.dll
  29. BIN Source/Extensions/SQLite/lib/System.Data.SQLite.Linq.pdb
  30. +1,973 −0 Source/Extensions/SQLite/lib/System.Data.SQLite.Linq.xml
  31. BIN Source/Extensions/SQLite/lib/System.Data.SQLite.dll
  32. BIN Source/Extensions/SQLite/lib/System.Data.SQLite.pdb
  33. +4,739 −0 Source/Extensions/SQLite/lib/System.Data.SQLite.xml
  34. BIN Source/Extensions/SQLite/lib/x64/SQLite.Interop.dll
  35. BIN Source/Extensions/SQLite/lib/x64/SQLite.Interop.pdb
  36. BIN Source/Extensions/SQLite/lib/x86/SQLite.Interop.dll
  37. BIN Source/Extensions/SQLite/lib/x86/SQLite.Interop.pdb
@@ -272,6 +272,33 @@ private void AddExportMethod(DTypeDesc/*!*/typedesc)
}
}

public void AddMethodToType(DTypeDesc typedesc, PhpMemberAttributes attributes, string func_name, Func<object, PhpStack, object> callback)
{
Debug.Assert(typedesc != null);

var name = new Name(func_name);
var method_desc = new PhpRoutineDesc(typedesc, attributes);

if (!typedesc.Methods.ContainsKey(name))
{
typedesc.Methods.Add(name, method_desc);
if (method_desc.Member == null)
{
PhpMethod method = new PhpMethod(name, (PhpRoutineDesc)method_desc, DummyArgFullCallback.Method, callback.Method);
method.WriteUp(PhpRoutineSignature.FromArgfullInfo(method, DummyArgFullCallback.Method));
method_desc.Member = method;
}
}
}

private static readonly Func<ScriptContext, object> DummyArgFullCallback = new Func<ScriptContext, object>(DummyArgFull);

[NeedsArgless()]
private static object DummyArgFull(ScriptContext context)
{
return null;
}

#endregion

internal void LoadModuleEntries(DModule/*!*/ module)
@@ -50,27 +50,31 @@
<Compile Include="PDO.Const.cs" />
<Compile Include="PDO.cs" />
<Compile Include="PDOAttributeType.cs" />
<Compile Include="PDOCaseConversion.cs" />
<Compile Include="PDOConfiguration.cs" />
<Compile Include="PDOConnection.cs" />
<Compile Include="PDOCursorType.cs" />
<Compile Include="PDOErrorMode.cs" />
<Compile Include="PDOException.cs" />
<Compile Include="PDOFetchType.cs" />
<Compile Include="PDOGlobalConfig.cs" />
<Compile Include="PDOLibraryDescriptor.cs" />
<Compile Include="PDOLocalConfig.cs" />
<Compile Include="PDONullHandling.cs" />
<Compile Include="PDOParamType.cs" />
<Compile Include="PDOStatement.cs" />
<Compile Include="PDOStatement.PHP.cs" />
<Compile Include="PDOStatics.cs" />
<Compile Include="PDOStatics.pdo_case_conversion.cs" />
<Compile Include="PDOStatics.pdo_cursor_type.cs" />
<Compile Include="PDOStatics.pdo_error_mode .cs" />
<Compile Include="PDOStatics.pdo_null_handling.cs" />
<Compile Include="PDOStatics.pdo_param_type.cs" />
<Compile Include="PDODriver.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\Extensions.snk">
<Link>Extensions.snk</Link>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ClassLibrary\ClassLibrary.csproj">
<Project>{D515E8F4-357C-4CAF-87C1-97D64C5F865A}</Project>
@@ -81,9 +85,6 @@
<Name>Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -5,14 +5,20 @@
using PHP.Core;
using System.ComponentModel;
using System.IO;
using System.Data;

namespace PHP.Library.Data
{
[ImplementsType]
public partial class PDO : PhpObject
{
private PDODriver m_driver;
private PDOConnection m_connection;
private IDbConnection m_con;
private IDbTransaction m_tx;

public PDODriver Driver { get { return this.m_driver; } }
public IDbTransaction Transaction { get { return this.m_tx; } }
public IDbConnection Connection { get { return this.m_con; } }

#region Constructor
/// <summary>
@@ -42,6 +48,27 @@ public static object __construct(object instance, PhpStack stack)
return ((PDO)instance).__construct(stack.Context, argDSN, argUsername, argPassword, argDriverOptions);
}

[PhpVisible]
[ImplementsMethod]
public object __construct(ScriptContext context, object argdsn)
{
return this.__construct(context, argdsn, null, null, null);
}

[PhpVisible]
[ImplementsMethod]
public object __construct(ScriptContext context, object argdsn, object argusername)
{
return this.__construct(context, argdsn, argusername, null, null);
}

[PhpVisible]
[ImplementsMethod]
public object __construct(ScriptContext context, object argdsn, object argusername, object argpassword)
{
return this.__construct(context, argdsn, argusername, argpassword, null);
}

[PhpVisible]
[ImplementsMethod]
public object __construct(ScriptContext context, object argdsn, object argusername, object argpassword, object argdriver_options)
@@ -74,13 +101,22 @@ public object __construct(ScriptContext context, object argdsn, object arguserna
{
throw new PDOException("Driver not found");
}
this.m_connection = this.m_driver.OpenConnection(context, items[1], username, password, argdriver_options);
this.m_con = this.m_driver.OpenConnection(context, items[1], username, password, argdriver_options);
}

if (this.m_driver == null || this.m_connection == null)
if (this.m_driver == null || this.m_con == null)
{
throw new PDOException("Invalid DSN");
}

//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;
}
#endregion
@@ -102,13 +138,35 @@ public static object getAvailableDrivers(object instance, PhpStack stack)
}
#endregion

#region Attributes
private readonly Dictionary<int, object> m_attributes = new Dictionary<int, object>();

public bool SetAttribute(int att, object value)
{
if (this.m_driver.IsValidAttributeValue(att, value))
{
return this.SetAttributeValueNoCheck(att, value);
}
else
{
return false;
}
}

internal bool SetAttributeValueNoCheck(int att, object value)
{
this.m_attributes[att] = value;
return true;
}
#endregion

#region setAttribute
[PhpVisible]
[ImplementsMethod]
public object setAttribute(ScriptContext context, object attribute, object value)
{
int attInt = PHP.Core.Convert.ObjectToInteger(attribute);
return this.m_connection.SetAttribute(attInt, value);
return this.SetAttribute(attInt, value);
}

[EditorBrowsable(EditorBrowsableState.Never)]
@@ -127,7 +185,16 @@ public static object setAttribute(object instance, PhpStack stack)
public object getAttribute(ScriptContext context, object attribute)
{
int attInt = PHP.Core.Convert.ObjectToInteger(attribute);
return this.m_connection.GetAttribute(attInt);
return this.GetAttribute(attInt, null);
}

public object GetAttribute(int attribute, object defaultValue)
{
if (this.m_attributes.ContainsKey(attribute))
{
return this.m_attributes[attribute];
}
return defaultValue;
}

[EditorBrowsable(EditorBrowsableState.Never)]
@@ -151,13 +218,13 @@ public object quote(ScriptContext context, object str)
[ImplementsMethod]
public object quote(ScriptContext context, object str, object parameter_type)
{
PDOStatics.pdo_param_type pt = PDOStatics.pdo_param_type.PDO_PARAM_STR;
PDOParamType pt = PDOParamType.PDO_PARAM_STR;
if (parameter_type != null)
{
int ptInt = PHP.Core.Convert.ObjectToInteger(parameter_type);
if (Enum.IsDefined(typeof(PDOStatics.pdo_param_type), ptInt))
if (Enum.IsDefined(typeof(PDOParamType), ptInt))
{
pt = (PDOStatics.pdo_param_type)ptInt;
pt = (PDOParamType)ptInt;
}
}
return this.m_driver.Quote(context, PHP.Core.Convert.ObjectToString(str), pt);
@@ -176,37 +243,48 @@ public static object quote(object instance, PhpStack stack)
#region query
[PhpVisible]
[ImplementsMethod]
[return: CastToFalse]
public object query(ScriptContext context, object statement)
{
return this.query(context, statement, null, null, null);
}

[PhpVisible]
[ImplementsMethod]
[return: CastToFalse]
public object query(ScriptContext context, object statement, object fetch_to_mode)
{
return this.query(context, statement, fetch_to_mode, null, null);
}

[PhpVisible]
[ImplementsMethod]
[return: CastToFalse]
public object query(ScriptContext context, object statement, object fetch_to_mode, object fetch_to_dest)
{
return this.query(context, statement, fetch_to_mode, fetch_to_dest, null);
}

[PhpVisible]
[ImplementsMethod]
[return: CastToFalse]
public object query(ScriptContext context, object statement, object fetch_to_mode, object fetch_to_dest, object fetch_to_args)
{
PDOStatement stmt = new PDOStatement(context, this.m_connection);
stmt.SetQuery(PHP.Core.Convert.ObjectToString(statement));
string query = PHP.Core.Convert.ObjectToString(statement);
PDOStatement stmt = this.m_driver.CreateStatement(context, this);
stmt.Init(query, null);
if (fetch_to_mode != null)
{
stmt.setFetchMode(context, fetch_to_mode, fetch_to_dest, fetch_to_args);
}
stmt.ExecuteInternal();
return stmt;
if (stmt.ExecuteStatement())
{
return stmt;
}
else
{
return false;
}
}

[EditorBrowsable(EditorBrowsableState.Never)]
@@ -221,8 +299,107 @@ public static object query(object instance, PhpStack stack)
}
#endregion

#region prepare
[PhpVisible]
[ImplementsMethod]
public object prepare(ScriptContext context, object statement)
{
return this.prepare(context, statement, null);
}
[PhpVisible]
[ImplementsMethod]
public object prepare(ScriptContext context, object statement, object driver_options)
{
string query = PHP.Core.Convert.ObjectToString(statement);
Dictionary<int, object> options = new Dictionary<int, object>();
if (driver_options != null && driver_options is PhpArray)
{
PhpArray arr = (PhpArray)driver_options;
foreach (var key in arr.Keys)
{
Debug.Assert(!key.IsInteger);
int keyInt = key.Integer;
options.Add(keyInt, arr[key]);
}
}

PDOStatement stmt = this.m_driver.CreateStatement(context, this);
stmt.Prepare(query, options);
return stmt;
}

public static object prepare(object instance, PhpStack stack)
{
object statement = stack.PeekValue(1);
object driver_options = stack.PeekValueOptional(2);
stack.RemoveFrame();
return ((PDO)instance).prepare(stack.Context, statement, driver_options);
}
#endregion

#region beginTransaction
[PhpVisible]
[ImplementsMethod]
public object beginTransaction(ScriptContext context)
{
if (this.m_tx != null)
{
return false;
}
this.m_tx = this.m_con.BeginTransaction();
return true;
}

public static object beginTransaction(object instance, PhpStack stack)
{
stack.RemoveFrame();
return ((PDO)instance).beginTransaction(stack.Context);
}
#endregion

#region commit
[PhpVisible]
[ImplementsMethod]
public object commit(ScriptContext context)
{
if (this.m_tx != null)
{
this.m_tx.Commit();
this.m_tx.Dispose();
this.m_tx = null;
return true;
}
return false;
}

public static object commit(object instance, PhpStack stack)
{
stack.RemoveFrame();
return ((PDO)instance).commit(stack.Context);
}
#endregion

#region rollback
[PhpVisible]
[ImplementsMethod]
public object rollback(ScriptContext context)
{
if (this.m_tx != null)
{
this.m_tx.Rollback();
this.m_tx.Dispose();
this.m_tx = null;
return true;
}
return false;

}

public static object rollback(object instance, PhpStack stack)
{
stack.RemoveFrame();
return ((PDO)instance).rollback(stack.Context);
}
#endregion
}
}

0 comments on commit 6c73ad3

Please sign in to comment.
You can’t perform that action at this time.