mail-archives/mono-list/2005-February/025832.html

135 строки
4.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Mono-list] Problem with datetime format and oracle...
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:danielmorgan%40verizon.net">
<META NAME="robots" CONTENT="index,nofollow">
<LINK REL="Previous" HREF="025809.html">
<LINK REL="Next" HREF="025838.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Mono-list] Problem with datetime format and oracle...
</H1>
<B>Daniel Morgan
</B>
<A HREF="mailto:danielmorgan%40verizon.net"
TITLE="[Mono-list] Problem with datetime format and oracle...">danielmorgan@verizon.net
</A><BR>
<I>Fri, 18 Feb 2005 23:51:27 -0500</I>
<P><UL>
<LI> Previous message: <A HREF="025809.html">[Mono-list] Problem with datetime format and oracle...
</A></li>
<LI> Next message: <A HREF="025838.html">[Mono-list] Problem with datetime format and oracle...
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#25832">[ date ]</a>
<a href="thread.html#25832">[ thread ]</a>
<a href="subject.html#25832">[ subject ]</a>
<a href="author.html#25832">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>The default date format for Oracle is 'DD-MMM-YY'. Example: '13-FEB-02'
The fix needs to be able to handle situations where the date format
could be changed via ALTER SESSION SET NLS_DATE_FORMAT, such as,
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
I have some ideas on how to solve it:
1. OCINlsGetInfo can be used to get the date format. However, once I
got this, I would need to reformat the date from OracleDateTime or
DateTime to Oracle's date and vice-vesa.
2. (I haven't tried this yet - create DllImport's for OCI functions
OCIDateTimeToText and OCIDateTimeFromText and calls these functions with
an explicit
date format string. Oracle's OCIDate can stay as an IntPtr and use
other OCI functions to deal with it.
3. There are even OCI functions to put the OCIDate into a byte array or
get the OCIDate from a byte array. OCIDateTimeFromArray and
OCIDateTimeToArray. DllImport's are needed for these functions too.
More info can be found in Oracle Call Interface Programmer's Guide.
<A HREF="http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96584/oci18m36.htm#512147">http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96584/oci18m36.htm#512147</A>
**
Here is working code so far...
private string GetSessionNlsDateFormat()
{
byte[] buffer = new Byte[64];
uint bufflen = (uint) buffer.Length;
ushort item = (ushort) OciNlsServiceType.DATEFORMAT;
IntPtr session = connection.Session;
int st = OciCalls.OCINlsGetInfo (session,
connection.ErrorHandle,
ref buffer, bufflen, item);
// Get length of returned string
int rsize = 0;
IntPtr env = connection.Environment;
OciCalls.OCICharSetToUnicode (env, null, buffer, out rsize);
// Get string
StringBuilder ret = new StringBuilder(rsize);
OciCalls.OCICharSetToUnicode (env, ret, buffer, out rsize);
string nlsDateFormat = ret.ToString ();
return nlsDateFormat;
}
internal static int OCINlsGetInfo (IntPtr hndl,
IntPtr errhp,
ref byte[] bufp,
uint buflen,
ushort item)
{
Trace.WriteLineIf(traceOci, &quot;OCINlsGetInfo&quot;, &quot;OCI&quot;);
return OciNativeCalls.OCINlsGetInfo (hndl, errhp, bufp,
buflen, item);
}
[DllImport (&quot;oci&quot;)]
internal static extern int OCINlsGetInfo (IntPtr hndl,
IntPtr errhp,
[In][Out] byte[] bufp,
uint buflen,
ushort item);
Hubert FONGARNAND wrote:
&gt;<i>I use mono to deal with an oracle database...
</I>&gt;<i>the date format of my oracle database is &quot;DD/MM/YY&quot;
</I>&gt;<i>but mono always send date like &quot;DD/MM/YYYY&quot;
</I>&gt;<i>my NLS_LANG parameter is : NLS_LANG=&quot;AMERICAN_AMERICA.WE8ISO8859P1&quot;
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i>
</I>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI> Previous message: <A HREF="025809.html">[Mono-list] Problem with datetime format and oracle...
</A></li>
<LI> Next message: <A HREF="025838.html">[Mono-list] Problem with datetime format and oracle...
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#25832">[ date ]</a>
<a href="thread.html#25832">[ thread ]</a>
<a href="subject.html#25832">[ subject ]</a>
<a href="author.html#25832">[ author ]</a>
</LI>
</UL>
</body></html>