-
Notifications
You must be signed in to change notification settings - Fork 2
/
FileMakerConnect.cs
112 lines (97 loc) · 3.16 KB
/
FileMakerConnect.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Odbc;
using System.Linq;
using System.Text;
namespace FileMakerConnect
{
public class FileMakerConnect : IDisposable
{
#region Private variables
private OdbcConnection _connection;
private OdbcCommand _command;
private OdbcDataAdapter _adapter;
#endregion
#region Properties
/// <summary>
/// The driver connection string used to connect to FileMaker via ODBC.
/// </summary>
public string ConnectionString { get; set; }
#endregion
#region Constructors
public FileMakerConnect()
{
_connection = new OdbcConnection();
_command = new OdbcCommand();
_command.Connection = _connection;
_adapter = new OdbcDataAdapter(_command);
}
public FileMakerConnect(string connectionString) : this()
{
ConnectionString = connectionString;
_connection.ConnectionString = ConnectionString;
}
#endregion
#region Methods
public DataTable ExecuteDataTable(string sql, OdbcParameter[] parameters)
{
DataTable table = new DataTable();
_command.CommandText = sql;
if (parameters != null && parameters.Length > 0)
_command.Parameters.AddRange(parameters);
_adapter.Fill(table);
return table;
}
public void ExecuteNonQuery(string sql, OdbcParameter[] parameters)
{
_command.CommandText = sql;
if (parameters != null && parameters.Length > 0)
_command.Parameters.AddRange(parameters);
_command.ExecuteNonQuery();
}
public object ExecuteScalar(string sql, OdbcParameter[] parameters)
{
_command.CommandText = sql;
if (parameters != null && parameters.Length > 0)
_command.Parameters.AddRange(parameters);
return _command.ExecuteScalar();
}
public T ExecuteScalar<T>(string sql, OdbcParameter[] parameters)
{
_command.CommandText = sql;
if (parameters != null && parameters.Length > 0)
_command.Parameters.AddRange(parameters);
return (T)_command.ExecuteScalar();
}
#endregion
#region Interface implementations
public void Dispose()
{
try
{
if (_connection != null && _connection.State != ConnectionState.Closed)
{
_connection.Close();
}
if (_connection != null)
{
_connection.Dispose();
_connection = null;
}
if (_command != null)
{
_command.Dispose();
_command = null;
}
if (_adapter != null)
{
_adapter.Dispose();
_adapter = null;
}
}
catch { }
}
#endregion
}
}