本文整理汇总了C#中System.Data.SqlClient.SqlCollation类的典型用法代码示例。如果您正苦于以下问题:C# SqlCollation类的具体用法?C# SqlCollation怎么用?C# SqlCollation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlCollation类属于System.Data.SqlClient命名空间,在下文中一共展示了SqlCollation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteBulkCopyValueSetupContinuation
// This is in its own method to avoid always allocating the lambda in WriteBulkCopyValue
private Task WriteBulkCopyValueSetupContinuation(Task internalWriteTask, Encoding saveEncoding, SqlCollation saveCollation, int saveCodePage, int saveLCID)
{
return internalWriteTask.ContinueWith<Task>(t =>
{
_defaultEncoding = saveEncoding;
_defaultCollation = saveCollation;
_defaultCodePage = saveCodePage;
_defaultLCID = saveLCID;
return t;
}, TaskScheduler.Default).Unwrap();
}
示例2: WriteBulkCopyValue
internal Task WriteBulkCopyValue(object value, SqlMetaDataPriv metadata, TdsParserStateObject stateObj, bool isSqlType, bool isDataFeed, bool isNull)
{
Debug.Assert(!isSqlType || value is INullable, "isSqlType is true, but value can not be type cast to an INullable");
Debug.Assert(!isDataFeed ^ value is DataFeed, "Incorrect value for isDataFeed");
Encoding saveEncoding = _defaultEncoding;
SqlCollation saveCollation = _defaultCollation;
int saveCodePage = _defaultCodePage;
int saveLCID = _defaultLCID;
Task resultTask = null;
Task internalWriteTask = null;
if (!(State == TdsParserState.OpenNotLoggedIn || State == TdsParserState.OpenLoggedIn))
{
throw ADP.ClosedConnectionError();
}
try
{
if (metadata.encoding != null)
{
_defaultEncoding = metadata.encoding;
}
if (metadata.collation != null)
{
_defaultCollation = metadata.collation;
_defaultLCID = _defaultCollation.LCID;
}
_defaultCodePage = metadata.codePage;
MetaType metatype = metadata.metaType;
int ccb = 0;
int ccbStringBytes = 0;
if (isNull)
{
// For UDT, remember we treat as binary even though it is a PLP
if (metatype.IsPlp && (metatype.NullableType != TdsEnums.SQLUDT || metatype.IsLong))
{
WriteLong(unchecked((long)TdsEnums.SQL_PLP_NULL), stateObj);
}
else if (!metatype.IsFixed && !metatype.IsLong && !metatype.IsVarTime)
{
WriteShort(TdsEnums.VARNULL, stateObj);
}
else
{
stateObj.WriteByte(TdsEnums.FIXEDNULL);
}
return resultTask;
}
if (!isDataFeed)
{
switch (metatype.NullableType)
{
case TdsEnums.SQLBIGBINARY:
case TdsEnums.SQLBIGVARBINARY:
case TdsEnums.SQLIMAGE:
case TdsEnums.SQLUDT:
ccb = (isSqlType) ? ((SqlBinary)value).Length : ((byte[])value).Length;
break;
case TdsEnums.SQLUNIQUEID:
ccb = GUID_SIZE; // that's a constant for guid
break;
case TdsEnums.SQLBIGCHAR:
case TdsEnums.SQLBIGVARCHAR:
case TdsEnums.SQLTEXT:
if (null == _defaultEncoding)
{
ThrowUnsupportedCollationEncountered(null); // stateObject only when reading
}
string stringValue = null;
if (isSqlType)
{
stringValue = ((SqlString)value).Value;
}
else
{
stringValue = (string)value;
}
ccb = stringValue.Length;
ccbStringBytes = _defaultEncoding.GetByteCount(stringValue);
break;
case TdsEnums.SQLNCHAR:
case TdsEnums.SQLNVARCHAR:
case TdsEnums.SQLNTEXT:
ccb = ((isSqlType) ? ((SqlString)value).Value.Length : ((string)value).Length) * 2;
break;
case TdsEnums.SQLXMLTYPE:
// Value here could be string or XmlReader
if (value is XmlReader)
{
value = MetaType.GetStringFromXml((XmlReader)value);
}
ccb = ((isSqlType) ? ((SqlString)value).Value.Length : ((string)value).Length) * 2;
break;
default:
//.........这里部分代码省略.........
示例3: GetCodePage
internal int GetCodePage(SqlCollation collation, TdsParserStateObject stateObj)
{
int codePage = 0;
if (0 != collation.sortId)
{
codePage = TdsEnums.CODE_PAGE_FROM_SORT_ID[collation.sortId];
Debug.Assert(0 != codePage, "GetCodePage accessed codepage array and produced 0!, sortID =" + ((Byte)(collation.sortId)).ToString((IFormatProvider)null));
}
else
{
int cultureId = collation.LCID;
bool success = false;
try
{
codePage = LocaleInterop.GetCodePageForLcid(cultureId);
// SqlHot 50001398: CodePage can be zero, but we should defer such errors until
// we actually MUST use the code page (i.e. don't error if no ANSI data is sent).
success = true;
}
catch (ArgumentException)
{
}
// If we failed, it is quite possible this is because certain culture id's
// were removed in Win2k and beyond, however Sql Server still supports them.
// In this case we will mask off the sort id (the leading 1). If that fails,
// or we have a culture id other than the cases below, we throw an error and
// throw away the rest of the results.
// Sometimes GetCultureInfo will return CodePage 0 instead of throwing.
// This should be treated as an error and functionality switches into the following logic.
if (!success || codePage == 0)
{
switch (cultureId)
{
case 0x10404: // zh-TW
case 0x10804: // zh-CN
case 0x10c04: // zh-HK
case 0x11004: // zh-SG
case 0x11404: // zh-MO
case 0x10411: // ja-JP
case 0x10412: // ko-KR
// If one of the following special cases, mask out sortId and
// retry.
cultureId = cultureId & 0x03fff;
try
{
codePage = LocaleInterop.GetCodePageForLcid(cultureId);
success = true;
}
catch (ArgumentException)
{
}
break;
case 0x827: // Mapping Non-supported Lithuanian code page to supported Lithuanian.
try
{
codePage = LocaleInterop.GetCodePageForLcid(0x427);
success = true;
}
catch (ArgumentException)
{
}
break;
default:
break;
}
if (!success)
{
ThrowUnsupportedCollationEncountered(stateObj);
}
Debug.Assert(codePage >= 0, string.Format("Invalid code page. codePage: {0}. cultureId: {1}", codePage, cultureId));
}
}
return codePage;
}
示例4: WriteCollation
private void WriteCollation(SqlCollation collation, TdsParserStateObject stateObj)
{
if (collation == null)
{
_physicalStateObj.WriteByte(0);
}
else
{
_physicalStateObj.WriteByte(sizeof(UInt32) + sizeof(byte));
WriteUnsignedInt(collation.info, _physicalStateObj);
_physicalStateObj.WriteByte(collation.sortId);
}
}
示例5: TryProcessCollation
internal bool TryProcessCollation(TdsParserStateObject stateObj, out SqlCollation collation)
{
SqlCollation newCollation = new SqlCollation();
if (!stateObj.TryReadUInt32(out newCollation.info))
{
collation = null;
return false;
}
if (!stateObj.TryReadByte(out newCollation.sortId))
{
collation = null;
return false;
}
collation = newCollation;
return true;
}
示例6: AreSame
static internal bool AreSame(SqlCollation a, SqlCollation b)
{
if (a == null || b == null)
{
return a == b;
}
else
{
return a.info == b.info && a.sortId == b.sortId;
}
}
示例7: SetString
// valid for character types: Char, VarChar, Text, NChar, NVarChar, NText
internal void SetString(string value, int offset, int length)
{
Debug.Assert(
SmiXetterAccessMap.IsSetterAccessValid(_metaData, SmiXetterTypeCode.XetString));
// ANSI types must convert to byte[] because that's the tool we have.
if (MetaDataUtilsSmi.IsAnsiType(_metaData.SqlDbType))
{
byte[] bytes;
// Optimize for common case of writing entire string
if (offset == 0 && value.Length <= length)
{
bytes = _stateObj.Parser._defaultEncoding.GetBytes(value);
}
else
{
char[] chars = value.ToCharArray(offset, length);
bytes = _stateObj.Parser._defaultEncoding.GetBytes(chars);
}
SetBytes(0, bytes, 0, bytes.Length);
SetBytesLength(bytes.Length);
}
else if (SqlDbType.Variant == _metaData.SqlDbType)
{
Debug.Assert(null != _variantType && SqlDbType.NVarChar == _variantType.SqlDbType, "Invalid variant type");
SqlCollation collation = new SqlCollation();
collation.LCID = checked((int)_variantType.LocaleId);
collation.SqlCompareOptions = _variantType.CompareOptions;
if (length * ADP.CharSize > TdsEnums.TYPE_SIZE_LIMIT)
{ // send as varchar for length greater than 4000
byte[] bytes;
// Optimize for common case of writing entire string
if (offset == 0 && value.Length <= length)
{
bytes = _stateObj.Parser._defaultEncoding.GetBytes(value);
}
else
{
bytes = _stateObj.Parser._defaultEncoding.GetBytes(value.ToCharArray(offset, length));
}
_stateObj.Parser.WriteSqlVariantHeader(9 + bytes.Length, TdsEnums.SQLBIGVARCHAR, 7, _stateObj);
_stateObj.Parser.WriteUnsignedInt(collation.info, _stateObj); // propbytes: collation.Info
_stateObj.WriteByte(collation.sortId); // propbytes: collation.SortId
_stateObj.Parser.WriteShort(bytes.Length, _stateObj); // propbyte: varlen
_stateObj.WriteByteArray(bytes, bytes.Length, 0);
}
else
{
_stateObj.Parser.WriteSqlVariantHeader(9 + length * ADP.CharSize, TdsEnums.SQLNVARCHAR, 7, _stateObj);
_stateObj.Parser.WriteUnsignedInt(collation.info, _stateObj); // propbytes: collation.Info
_stateObj.WriteByte(collation.sortId); // propbytes: collation.SortId
_stateObj.Parser.WriteShort(length * ADP.CharSize, _stateObj); // propbyte: varlen
_stateObj.Parser.WriteString(value, length, offset, _stateObj);
}
_variantType = null;
}
else if (_isPlp)
{
// Send the string as a complete PLP chunk.
_stateObj.Parser.WriteLong(length * ADP.CharSize, _stateObj); // PLP total length
_stateObj.Parser.WriteInt(length * ADP.CharSize, _stateObj); // Chunk length
_stateObj.Parser.WriteString(value, length, offset, _stateObj); // Data
if (length != 0)
{
_stateObj.Parser.WriteInt(TdsEnums.SQL_PLP_CHUNK_TERMINATOR, _stateObj); // Terminator
}
}
else
{
_stateObj.Parser.WriteShort(length * ADP.CharSize, _stateObj);
_stateObj.Parser.WriteString(value, length, offset, _stateObj);
}
}
示例8: GetCodePage
internal int GetCodePage(SqlCollation collation, TdsParserStateObject stateObj) {
int codePage = 0;
if (0 != collation.sortId) {
codePage = TdsEnums.CODE_PAGE_FROM_SORT_ID[collation.sortId];
Debug.Assert(0 != codePage, "GetCodePage accessed codepage array and produced 0!, sortID =" + ((Byte)(collation.sortId)).ToString((IFormatProvider)null));
}
else {
int cultureId = collation.LCID;
bool success = false;
try {
codePage = CultureInfo.GetCultureInfo(cultureId).TextInfo.ANSICodePage;
// SqlHot 50001398: CodePage can be zero, but we should defer such errors until
// we actually MUST use the code page (i.e. don't error if no ANSI data is sent).
success = true;
}
catch (ArgumentException e) {
ADP.TraceExceptionWithoutRethrow(e);
}
// If we failed, it is quite possible this is because certain culture id's
// were removed in Win2k and beyond, however Sql Server still supports them.
// There is a workaround for the culture id's listed below, which is to mask
// off the sort id (the leading 1). If that fails, or we have a culture id
// other than the special cases below, we throw an error and throw away the
// rest of the results. For additional info, see MDAC 65963.
// SqlHot 50001398: Sometimes GetCultureInfo will return CodePage 0 instead of throwing.
// treat this as an error also, and switch into the special-case logic.
if (!success || codePage == 0) {
CultureInfo ci = null;
switch (cultureId) {
case 0x10404: // zh-TW
case 0x10804: // zh-CN
case 0x10c04: // zh-HK
case 0x11004: // zh-SG
case 0x11404: // zh-MO
case 0x10411: // ja-JP
case 0x10412: // ko-KR
// If one of the following special cases, mask out sortId and
// retry.
cultureId = cultureId & 0x03fff;
try {
ci = new CultureInfo(cultureId);
success = true;
}
catch (ArgumentException e) {
ADP.TraceExceptionWithoutRethrow(e);
}
break;
case 0x827: // Non-supported Lithuanian code page, map it to supported Lithuanian.
try {
ci = new CultureInfo(0x427);
success = true;
}
catch (ArgumentException e) {
ADP.TraceExceptionWithoutRethrow(e);
}
break;
default:
break;
}
// I don't believe we should still be in failure case, but just in case.
if (!success) {
ThrowUnsupportedCollationEncountered(stateObj);
}
if (null != ci) {
codePage = ci.TextInfo.ANSICodePage;
}
}
}
return codePage;
}
示例9: SetString
internal void SetString(string value, int offset, int length)
{
if (MetaDataUtilsSmi.IsAnsiType(this._metaData.SqlDbType))
{
byte[] bytes;
if ((offset == 0) && (value.Length <= length))
{
bytes = this._stateObj.Parser._defaultEncoding.GetBytes(value);
}
else
{
char[] chars = value.ToCharArray(offset, length);
bytes = this._stateObj.Parser._defaultEncoding.GetBytes(chars);
}
this.SetBytes(0L, bytes, 0, bytes.Length);
this.SetBytesLength((long) bytes.Length);
}
else if (SqlDbType.Variant == this._metaData.SqlDbType)
{
SqlCollation collation = new SqlCollation {
LCID = (int) this._variantType.LocaleId,
SqlCompareOptions = this._variantType.CompareOptions
};
if ((length * ADP.CharSize) > 0x1f40)
{
byte[] buffer;
if ((offset == 0) && (value.Length <= length))
{
buffer = this._stateObj.Parser._defaultEncoding.GetBytes(value);
}
else
{
buffer = this._stateObj.Parser._defaultEncoding.GetBytes(value.ToCharArray(offset, length));
}
this._stateObj.Parser.WriteSqlVariantHeader(9 + buffer.Length, 0xa7, 7, this._stateObj);
this._stateObj.Parser.WriteUnsignedInt(collation.info, this._stateObj);
this._stateObj.Parser.WriteByte(collation.sortId, this._stateObj);
this._stateObj.Parser.WriteShort(buffer.Length, this._stateObj);
this._stateObj.Parser.WriteByteArray(buffer, buffer.Length, 0, this._stateObj);
}
else
{
this._stateObj.Parser.WriteSqlVariantHeader(9 + (length * ADP.CharSize), 0xe7, 7, this._stateObj);
this._stateObj.Parser.WriteUnsignedInt(collation.info, this._stateObj);
this._stateObj.Parser.WriteByte(collation.sortId, this._stateObj);
this._stateObj.Parser.WriteShort(length * ADP.CharSize, this._stateObj);
this._stateObj.Parser.WriteString(value, length, offset, this._stateObj);
}
this._variantType = null;
}
else if (this._isPlp)
{
this._stateObj.Parser.WriteLong((long) (length * ADP.CharSize), this._stateObj);
this._stateObj.Parser.WriteInt(length * ADP.CharSize, this._stateObj);
this._stateObj.Parser.WriteString(value, length, offset, this._stateObj);
if (length != 0)
{
this._stateObj.Parser.WriteInt(0, this._stateObj);
}
}
else
{
this._stateObj.Parser.WriteShort(length * ADP.CharSize, this._stateObj);
this._stateObj.Parser.WriteString(value, length, offset, this._stateObj);
}
}
示例10: GetCodePage
internal int GetCodePage(SqlCollation collation, TdsParserStateObject stateObj)
{
int aNSICodePage = 0;
if (collation.sortId != 0)
{
return TdsEnums.CODE_PAGE_FROM_SORT_ID[collation.sortId];
}
int lCID = collation.LCID;
bool flag = false;
try
{
aNSICodePage = CultureInfo.GetCultureInfo(lCID).TextInfo.ANSICodePage;
flag = true;
}
catch (ArgumentException exception3)
{
ADP.TraceExceptionWithoutRethrow(exception3);
}
if (!flag || (aNSICodePage == 0))
{
CultureInfo info = null;
switch (lCID)
{
case 0x10411:
case 0x10412:
case 0x10404:
case 0x11004:
case 0x11404:
case 0x10804:
case 0x10c04:
lCID &= 0x3fff;
try
{
info = new CultureInfo(lCID);
flag = true;
}
catch (ArgumentException exception2)
{
ADP.TraceExceptionWithoutRethrow(exception2);
}
break;
case 0x827:
try
{
info = new CultureInfo(0x427);
flag = true;
}
catch (ArgumentException exception)
{
ADP.TraceExceptionWithoutRethrow(exception);
}
break;
}
if (!flag)
{
this.ThrowUnsupportedCollationEncountered(stateObj);
}
if (info != null)
{
aNSICodePage = info.TextInfo.ANSICodePage;
}
}
return aNSICodePage;
}
示例11: Reset
public void Reset() {
_database = null;
_collation = null;
_language = null;
if (_deltaDirty) {
_delta = new SessionStateRecord[_maxNumberOfSessionStates];
_deltaDirty = false;
}
_unrecoverableStatesCount = 0;
}
示例12: SessionData
public SessionData(SessionData recoveryData) {
_initialDatabase = recoveryData._initialDatabase;
_initialCollation = recoveryData._initialCollation;
_initialLanguage = recoveryData._initialLanguage;
_resolvedAliases = recoveryData._resolvedAliases;
for (int i = 0; i < _maxNumberOfSessionStates; i++) {
if (recoveryData._initialState[i] != null) {
_initialState[i] = (byte[])recoveryData._initialState[i].Clone();
}
}
}
示例13: TryProcessEnvChange
private bool TryProcessEnvChange(int tokenLength, TdsParserStateObject stateObj, out SqlEnvChange[] sqlEnvChange)
{
// There could be multiple environment change messages following this token.
byte byteLength;
int processedLength = 0;
int nvalues = 0;
SqlEnvChange[] envarray = new SqlEnvChange[3]; // Why is this hardcoded to 3?
sqlEnvChange = null;
while (tokenLength > processedLength)
{
if (nvalues >= envarray.Length)
{
// This is a rare path. Most of the time we will have 1 or 2 envchange data streams.
SqlEnvChange[] newenvarray = new SqlEnvChange[envarray.Length + 3];
for (int ii = 0; ii < envarray.Length; ii++)
newenvarray[ii] = envarray[ii];
envarray = newenvarray;
}
SqlEnvChange env = new SqlEnvChange();
if (!stateObj.TryReadByte(out env.type))
{
return false;
}
envarray[nvalues] = env;
nvalues++;
switch (env.type)
{
case TdsEnums.ENV_DATABASE:
case TdsEnums.ENV_LANG:
if (!TryReadTwoStringFields(env, stateObj))
{
return false;
}
break;
case TdsEnums.ENV_CHARSET:
// we copied this behavior directly from luxor - see charset envchange
// section from sqlctokn.c
if (!TryReadTwoStringFields(env, stateObj))
{
return false;
}
if (env.newValue == TdsEnums.DEFAULT_ENGLISH_CODE_PAGE_STRING)
{
_defaultCodePage = TdsEnums.DEFAULT_ENGLISH_CODE_PAGE_VALUE;
_defaultEncoding = System.Text.Encoding.GetEncoding(_defaultCodePage);
}
else
{
Debug.Assert(env.newValue.Length > TdsEnums.CHARSET_CODE_PAGE_OFFSET, "TdsParser.ProcessEnvChange(): charset value received with length <=10");
string stringCodePage = env.newValue.Substring(TdsEnums.CHARSET_CODE_PAGE_OFFSET);
_defaultCodePage = Int32.Parse(stringCodePage, NumberStyles.Integer, CultureInfo.InvariantCulture);
_defaultEncoding = System.Text.Encoding.GetEncoding(_defaultCodePage);
}
break;
case TdsEnums.ENV_PACKETSIZE:
// take care of packet size right here
Debug.Assert(stateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
if (!TryReadTwoStringFields(env, stateObj))
{
// Changing packet size does not support retry, should not pend"
throw SQL.SynchronousCallMayNotPend();
}
// Only set on physical state object - this should only occur on LoginAck prior
// to MARS initialization!
Int32 packetSize = Int32.Parse(env.newValue, NumberStyles.Integer, CultureInfo.InvariantCulture);
if (_physicalStateObj.SetPacketSize(packetSize))
{
// If packet size changed, we need to release our SNIPackets since
// those are tied to packet size of connection.
_physicalStateObj.ClearAllWritePackets();
// Update SNI ConsumerInfo value to be resulting packet size
UInt32 unsignedPacketSize = (UInt32)packetSize;
UInt32 result = SNINativeMethodWrapper.SNISetInfo(_physicalStateObj.Handle, SNINativeMethodWrapper.QTypes.SNI_QUERY_CONN_BUFSIZE, ref unsignedPacketSize);
Debug.Assert(result == TdsEnums.SNI_SUCCESS, "Unexpected failure state upon calling SNISetInfo");
}
break;
case TdsEnums.ENV_LOCALEID:
if (!TryReadTwoStringFields(env, stateObj))
{
return false;
}
_defaultLCID = Int32.Parse(env.newValue, NumberStyles.Integer, CultureInfo.InvariantCulture);
//.........这里部分代码省略.........
示例14: CopyFrom
internal virtual void CopyFrom(SqlMetaDataPriv original)
{
this.type = original.type;
this.tdsType = original.tdsType;
this.precision = original.precision;
this.scale = original.scale;
this.length = original.length;
this.collation = original.collation;
this.codePage = original.codePage;
this.encoding = original.encoding;
this.isNullable = original.isNullable;
this.xmlSchemaCollectionDatabase = original.xmlSchemaCollectionDatabase;
this.xmlSchemaCollectionOwningSchema = original.xmlSchemaCollectionOwningSchema;
this.xmlSchemaCollectionName = original.xmlSchemaCollectionName;
this.metaType = original.metaType;
}
示例15: CopyFrom
internal virtual void CopyFrom(SqlMetaDataPriv original) {
this.type = original.type;
this.tdsType = original.tdsType;
this.precision = original.precision;
this.scale = original.scale;
this.length = original.length;
this.collation = original.collation;
this.codePage = original.codePage;
this.encoding = original.encoding;
this.isNullable = original.isNullable;
this.isMultiValued = original.isMultiValued;
this.udtDatabaseName = original.udtDatabaseName;
this.udtSchemaName = original.udtSchemaName;
this.udtTypeName = original.udtTypeName;
this.udtAssemblyQualifiedName = original.udtAssemblyQualifiedName;
this.udtType = original.udtType;
this.xmlSchemaCollectionDatabase = original.xmlSchemaCollectionDatabase;
this.xmlSchemaCollectionOwningSchema = original.xmlSchemaCollectionOwningSchema;
this.xmlSchemaCollectionName = original.xmlSchemaCollectionName;
this.metaType = original.metaType;
//
this.structuredTypeDatabaseName = original.structuredTypeDatabaseName;
this.structuredTypeSchemaName = original.structuredTypeSchemaName;
this.structuredTypeName = original.structuredTypeName;
this.structuredFields = original.structuredFields;
}