Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Commit

Permalink
2003-01-15 Gonzalo Paniagua Javier <gonzalo@ximian.com>
Browse files Browse the repository at this point in the history
	* INSTALL:
	* Makefile:
	* server/Makefile:
	* server/server.exe.config:
	* server/web.config:
	* test/dbpage1.aspx:
	* test/dbpage2.aspx: make the database accessing samples take some
	parameters from the configuration file to choose the IDbConnection
	and documented it.

svn path=/trunk/xsp/; revision=10530
  • Loading branch information
gonzalop committed Jan 15, 2003
1 parent de59603 commit d20b09d
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 74 deletions.
4 changes: 4 additions & 0 deletions INSTALL
Expand Up @@ -15,3 +15,7 @@ Steps for installing the server:

Or you can use the --port command line option.

If you're gonna try the samples that use a database (such as dbpage1.aspx),
you may need to modify the values of DBProviderAssembly, DBConnectionType
and/or DbConnectionString in server.exe.config file.

5 changes: 5 additions & 0 deletions Makefile
Expand Up @@ -10,6 +10,11 @@ install: all
@echo 'Now cd to server/test and run: mono server.exe or ./server.exe'
@echo 'Then point your web browser to http://127.0.0.1:8080/'
@echo 'You can change the default port (8080) in the server.exe.config file.'
@echo ""
@echo "If you're gonna try the samples that use a database (such as dbpage1.aspx),"
@echo "you may need to modify the values of DBProviderAssembly, DBConnectionType"
@echo "and/or DbConnectionString in server.exe.config file."

@echo ""
@echo 'Enjoy!'
@echo "-------------"
Expand Down
8 changes: 8 additions & 0 deletions server/ChangeLog
@@ -1,3 +1,11 @@
2003-01-15 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* Makefile:
* server.exe.config:
* web.config: make the database accessing samples take some
parameters from the configuration file to choose the IDbConnection
and documented it.

2003-01-14 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* MonoWorkerRequest.cs:
Expand Down
4 changes: 2 additions & 2 deletions server/Makefile
Expand Up @@ -23,8 +23,8 @@ install: server.exe web.config global.asax
mkdir -p test/bin
cp server.exe *.config global.asax test
cp server.exe test/bin
test -f server.dbg && cp server.dbg test
test -f server.dbg && cp server.dbg test/bin
-test -f server.dbg && cp server.dbg test
-test -f server.dbg && cp server.dbg test/bin
cp ../test/*.aspx ../test/*.ascx ../test/*.xml ../test/*.png test
cp ../test/*.dll test/bin
# Remove next line once assembly loading is fixed.
Expand Down
6 changes: 6 additions & 0 deletions server/server.exe.config
Expand Up @@ -2,6 +2,12 @@
<configuration>
<appSettings>
<add key="MonoServerPort" value="8080"/>
<add key="DBProviderAssembly"
value="Mono.Data.PostgreSqlClient"/>
<add key="DBConnectionType"
value="Mono.Data.PostgreSqlClient.PgSqlConnection"/>
<add key="DBConnectionString"
value="hostaddr=127.0.0.1;user=monotest;password=monotest;dbname=monotest"/>
</appSettings>
</configuration>

6 changes: 6 additions & 0 deletions server/web.config
Expand Up @@ -6,6 +6,12 @@
</system.web>
<appSettings>
<add key="MonoServerPort" value="8080"/>
<add key="DBProviderAssembly"
value="Mono.Data.PostgreSqlClient"/>
<add key="DBConnectionType"
value="Mono.Data.PostgreSqlClient.PgSqlConnection"/>
<add key="DBConnectionString"
value="hostaddr=127.0.0.1;user=monotest;password=monotest;dbname=monotest"/>
</appSettings>
</configuration>

7 changes: 7 additions & 0 deletions test/ChangeLog
@@ -1,3 +1,10 @@
2003-01-15 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* dbpage1.aspx:
* dbpage2.aspx: make the database accessing samples take some
parameters from the configuration file to choose the IDbConnection
and documented it.

2003-01-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* web_datagrid.aspx: simple datagrid test.
Expand Down
128 changes: 90 additions & 38 deletions test/dbpage1.aspx
@@ -1,42 +1,73 @@
<%@ language="C#" %>
<%@ import namespace="System" %>
<%@ import namespace="System.Configuration" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Reflection" %>

<html>
<script runat=server>
// FIXME: temporary hack to get this working
static Assembly dbAssembly = null;
static Type typ = null;
static Type cncType = null;
/* You must setup a user (monotest, pw=monotest), a database
*called monotest with a table called test which has two columns:
*person and email
*/
IDbConnection cnc;
void Page_Init (object sender, EventArgs e)
void GetConnectionData (out string providerAssembly, out string cncTypeName, out string cncString)
{
// FIXME: temporary hack to get this working until
// we can use global.asax file (no support fot it yet)
// to dynamically load an assembly
if(dbAssembly == null) {
const string connectionTypeName = "Mono.Data.PostgreSqlClient.PgSqlConnection";
const string providerAssemblyName = "Mono.Data.PostgreSqlClient";
dbAssembly = Assembly.Load (providerAssemblyName);
typ = dbAssembly.GetType (connectionTypeName);
providerAssembly = null;
cncTypeName = null;
cncString = null;
NameValueCollection config = ConfigurationSettings.AppSettings as NameValueCollection;
if (config != null) {
foreach (string s in config.Keys) {
if (0 == String.Compare ("DBProviderAssembly", s, true)) {
providerAssembly = config [s];
} else if (0 == String.Compare ("DBConnectionType", s, true)) {
cncTypeName = config [s];
} else if (0 == String.Compare ("DBConnectionString", s, true)) {
cncString = config [s];
}
}
}
cnc = (IDbConnection) Activator.CreateInstance (typ);
if (providerAssembly == null || providerAssembly == "")
providerAssembly = "Mono.Data.PostgreSqlClient";
string connectionString = "hostaddr=127.0.0.1;" +
"user=monotest;" +
"password=monotest;" +
"dbname=monotest";
if (cncTypeName == null || cncTypeName == "")
cncTypeName = "Mono.Data.PostgreSqlClient.PgSqlConnection";
if (cncString == null || cncString == "")
cncString = "hostaddr=127.0.0.1;user=monotest;password=monotest;dbname=monotest";
}
void ShowError (Exception exc)
{
noDBLine.InnerHtml += "<p><b>The error was:</b>\n<pre> " + exc + "</pre><p>";
theForm.Visible = false;
noDBLine.Visible = true;
}
IDbConnection cnc;
void Page_Init (object sender, EventArgs e)
{
string connectionTypeName;
string providerAssemblyName;
string cncString;
cnc.ConnectionString = connectionString;
cnc.Open ();
GetConnectionData (out providerAssemblyName, out connectionTypeName, out cncString);
if (cncType == null) {
Assembly dbAssembly = Assembly.Load (providerAssemblyName);
cncType = dbAssembly.GetType (connectionTypeName, true);
if (!typeof (IDbConnection).IsAssignableFrom (cncType))
throw new ApplicationException ("The type '" + cncType +
"' does not implement IDbConnection.\n" +
"Check 'DbConnectionType' in server.exe.config.");
}
cnc = (IDbConnection) Activator.CreateInstance (cncType);
cnc.ConnectionString = cncString;
try {
cnc.Open ();
} catch (Exception exc) {
ShowError (exc);
cnc = null;
}
}
void Page_Load (object sender, EventArgs e)
Expand All @@ -51,10 +82,9 @@
void Filter_Changed (object sender, EventArgs e)
{
UpdateTable (PersonFilter.Text, MailFilter.Text);
}
private void UpdateTable (string filterPerson, string filterMail)
void UpdateTable (string filterPerson, string filterMail)
{
IDbCommand selectCommand = cnc.CreateCommand();
IDataReader reader;
Expand All @@ -64,16 +94,19 @@
"email like '" + filterMail + "'";
selectCommand.CommandText = selectCmd;
reader = selectCommand.ExecuteReader ();
while (reader.Read ()) {
TableRow row = new TableRow ();
for (int i = 0; i < reader.FieldCount; i++) {
TableCell cell = new TableCell ();
cell.Controls.Add (new LiteralControl (reader.GetValue (i).ToString ()));
row.Cells.Add (cell);
try {
reader = selectCommand.ExecuteReader ();
while (reader.Read ()) {
TableRow row = new TableRow ();
for (int i = 0; i < reader.FieldCount; i++) {
TableCell cell = new TableCell ();
cell.Controls.Add (new LiteralControl (reader.GetValue (i).ToString ()));
row.Cells.Add (cell);
}
myTable.Rows.Add (row);
}
myTable.Rows.Add (row);
} catch (Exception exc) {
ShowError (exc);
}
}
Expand All @@ -82,8 +115,27 @@
<title>Some DB testing</title>
</head>
<body>
<span runat="server" visible="false" id="noDBLine">
<h3>Database Error</h3>
Sorry, a database error has occurred.
<p>
You should set up a database for user <i>'monotest'</i>,
password <i>'monotest'</i> and dbname <i>'monotest'</i>.
<p>
Then modify the variables DBProviderAssembly, DBConnectionType and
DBConnectionString in server.exe.config file to fit your needs.
<p>
The database should have a table called customers created with the following command (or similar):
<pre>
CREATE TABLE "test" (
"person" character varying(256) NOT NULL,
"email" character varying(256) NOT NULL
);

</pre>
</span>
<form id="theForm" runat="server">
Choose the SQL filters and click 'Submit'.
<form runat="server">
<asp:Label Text="Person Filter: " />
<asp:TextBox id="PersonFilter" Text="" TextMode="singleLine" OnTextChanged="Filter_Changed" runat="server" maxlength=40 />
<p>
Expand Down

0 comments on commit d20b09d

Please sign in to comment.