Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DLinq / Dlinq / SqlClient / SqlBuilder.cs / 1305376 / SqlBuilder.cs
using System; using System.Collections.Generic; using System.Diagnostics; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; namespace System.Data.Linq.SqlClient { using System.Data.Linq.Mapping; using System.Data.Linq.Provider; using System.Diagnostics.CodeAnalysis; ////// Class for building up SQL DDL commands. /// internal static class SqlBuilder { internal static string GetCreateDatabaseCommand(string catalog, string dataFilename, string logFilename) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("CREATE DATABASE {0}", SqlIdentifier.QuoteIdentifier(catalog)); if (dataFilename != null) { sb.AppendFormat(" ON PRIMARY (NAME='{0}', FILENAME='{1}')", Path.GetFileName(dataFilename), dataFilename); sb.AppendFormat(" LOG ON (NAME='{0}', FILENAME='{1}')", Path.GetFileName(logFilename), logFilename); } return sb.ToString(); } internal static string GetDropDatabaseCommand(string catalog) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("DROP DATABASE {0}", SqlIdentifier.QuoteIdentifier(catalog)); return sb.ToString(); } internal static string GetCreateSchemaForTableCommand(MetaTable table) { StringBuilder sb = new StringBuilder(); Listparts = new List (SqlIdentifier.GetCompoundIdentifierParts(table.TableName)); // table names look like this in Yukon (according to MSDN): // [ database_name . [ schema_name ] . | schema_name . ] table_name // ... which means that either way, the schema name is the second to last part. if ((parts.Count) < 2) { return null; } string schema = parts[parts.Count - 2]; if (String.Compare(schema, "DBO", StringComparison.OrdinalIgnoreCase) != 0 && String.Compare(schema, "[DBO]", StringComparison.OrdinalIgnoreCase) != 0) { sb.AppendFormat("CREATE SCHEMA {0}", SqlIdentifier.QuoteIdentifier(schema)); } return sb.ToString(); } internal static string GetCreateTableCommand(MetaTable table) { StringBuilder sb = new StringBuilder(); StringBuilder decl = new StringBuilder(); BuildFieldDeclarations(table, decl); sb.AppendFormat("CREATE TABLE {0}", SqlIdentifier.QuoteCompoundIdentifier(table.TableName)); sb.Append("("); sb.Append(decl.ToString()); decl = new StringBuilder(); BuildPrimaryKey(table, decl); if (decl.Length > 0) { string name = String.Format(Globalization.CultureInfo.InvariantCulture, "PK_{0}", table.TableName); sb.Append(", "); sb.AppendLine(); sb.AppendFormat(" CONSTRAINT {0} PRIMARY KEY ({1})", SqlIdentifier.QuoteIdentifier(name), decl.ToString()); } sb.AppendLine(); sb.Append(" )"); return sb.ToString(); } internal static void BuildFieldDeclarations(MetaTable table, StringBuilder sb) { int n = 0; Dictionary
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridCheckBoxColumn.cs
- SymLanguageType.cs
- TextWriter.cs
- XmlSchemaInferenceException.cs
- Grammar.cs
- SqlMethodAttribute.cs
- HttpTransportBindingElement.cs
- GAC.cs
- nulltextnavigator.cs
- SerializationException.cs
- HasCopySemanticsAttribute.cs
- GACMembershipCondition.cs
- DocumentGridContextMenu.cs
- PageHandlerFactory.cs
- ManipulationPivot.cs
- PersonalizableAttribute.cs
- RelOps.cs
- CapabilitiesAssignment.cs
- InstanceLockedException.cs
- TypeUtils.cs
- Int64AnimationBase.cs
- RelOps.cs
- DisplayNameAttribute.cs
- DesignerTextViewAdapter.cs
- UrlMappingCollection.cs
- ScriptControlDescriptor.cs
- WsatConfiguration.cs
- CodePageUtils.cs
- DynamicRouteExpression.cs
- PermissionSetEnumerator.cs
- DataGridViewCheckBoxCell.cs
- Matrix3DStack.cs
- ListViewItemEventArgs.cs
- DbRetry.cs
- AssemblyAttributesGoHere.cs
- UrlPropertyAttribute.cs
- WebPartDisplayModeCancelEventArgs.cs
- SystemIPAddressInformation.cs
- BuildProvider.cs
- DataPagerCommandEventArgs.cs
- CodeVariableDeclarationStatement.cs
- QueryConverter.cs
- OleDbPropertySetGuid.cs
- BuildManager.cs
- MediaContext.cs
- SqlNamer.cs
- TraceUtils.cs
- SqlPersonalizationProvider.cs
- RtfControlWordInfo.cs
- TypedReference.cs
- MediaPlayer.cs
- DtrList.cs
- XPathNodeList.cs
- SafeUserTokenHandle.cs
- X509AsymmetricSecurityKey.cs
- BaseTemplateBuildProvider.cs
- CLSCompliantAttribute.cs
- UnionCqlBlock.cs
- CodeDOMUtility.cs
- SimpleWorkerRequest.cs
- NotSupportedException.cs
- MsmqInputMessage.cs
- COM2ExtendedBrowsingHandler.cs
- TemplateBamlRecordReader.cs
- SoapHeaderException.cs
- VirtualDirectoryMappingCollection.cs
- SchemaTableOptionalColumn.cs
- DPTypeDescriptorContext.cs
- IList.cs
- StartUpEventArgs.cs
- ConfigurationElementCollection.cs
- ResourceManagerWrapper.cs
- DictionaryEditChange.cs
- updateconfighost.cs
- MarshalByRefObject.cs
- CalendarAutomationPeer.cs
- XamlWriter.cs
- ListViewUpdateEventArgs.cs
- AndCondition.cs
- SqlSelectStatement.cs
- StreamingContext.cs
- SymbolTable.cs
- ExeContext.cs
- DependencyPropertyAttribute.cs
- CookieParameter.cs
- NativeActivityContext.cs
- ActivityExecutionContextCollection.cs
- TextEditorLists.cs
- RuleDefinitions.cs
- PipelineModuleStepContainer.cs
- EnumerableRowCollectionExtensions.cs
- WriteableBitmap.cs
- NoResizeSelectionBorderGlyph.cs
- LinkButton.cs
- ZeroOpNode.cs
- AgileSafeNativeMemoryHandle.cs
- documentsequencetextview.cs
- DrawingCollection.cs
- ObjectCloneHelper.cs
- ServiceHostingEnvironment.cs