Datei: Provider/SqliteProvider/NDO.Sqlite/Generator.cs

Last Commit (2a2e7ba)
1 //
2 // Copyright (c) 2002-2019 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Reflection;
25 using System.Text;
26 using System.Text.RegularExpressions;
27 using System.Collections;
28 using System.Data;
29 using System.IO;
30 using NDO;
31 using NDOInterfaces;
32
33 namespace NDO.SqliteProvider
34 {
35 ····public class SqliteGenerator : AbstractSQLGenerator
36 ····{
37
38 ········public SqliteGenerator()
39 ········{············
40 ········}
41
42 ········public override string ProviderName
43 ········{
44 ············get { return "Sqlite"; }
45 ········}
46
47 ········public override string DropTable(string tableName)
48 ········{
49 ············return "DROP TABLE " + tableName + ";";
50 ········}
51
52
53 ········public override bool LengthAllowed(Type t)
54 ········{
55 ············return true;
56 ········}
57
58 ········public override bool LengthAllowed(string dbType)
59 ········{
60 ············return true;
61 ········}
62
63 ········public override string DbTypeFromType(Type t, int size)
64 ········{
65 ············// CLOBs: Strings don't have a limit in Sqlite. So there is nothing to do.
66 ············return NDO.SqliteProvider.Provider.GetInternalDbType( t ).ToString();
67 ········}
68
69 public override string AutoIncrementColumn( string columnName, Type dataType, string columnType, string width)
70 ········{
71 return columnName + " Integer PRIMARY KEY AUTOINCREMENT";
 
72 ········}
73
74 ········public override bool HasSpecialAutoIncrementColumnFormat
75 ········{
76 ············get { return true; }
77 ········}
78
79 ········public override PrimaryConstraintPlacement PrimaryConstraintPlacement
80 ········{
81 ············get { return PrimaryConstraintPlacement.InColumn; }
82 ········}
83
84 ········public override string PrimaryKeyColumn(string columnName, Type dataType, string columnType, string width)
85 ········{
86 ············string coldef = columnName + " " + columnType;
87 ············if (dataType == typeof(string))
88 ················coldef += '(' + width + ')';
89 ············return coldef + " PRIMARY KEY";
90 ········}
91
92 ····}
93
94 }
95
New Commit (1e68dc7)
1 //
2 // Copyright (c) 2002-2019 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Reflection;
25 using System.Text;
26 using System.Text.RegularExpressions;
27 using System.Collections;
28 using System.Data;
29 using System.IO;
30 using NDO;
31 using NDOInterfaces;
32
33 namespace NDO.SqliteProvider
34 {
35 ····public class SqliteGenerator : AbstractSQLGenerator
36 ····{
37
38 ········public SqliteGenerator()
39 ········{············
40 ········}
41
42 ········public override string ProviderName
43 ········{
44 ············get { return "Sqlite"; }
45 ········}
46
47 ········public override string DropTable(string tableName)
48 ········{
49 ············return "DROP TABLE " + tableName + ";";
50 ········}
51
52
53 ········public override bool LengthAllowed(Type t)
54 ········{
55 ············return true;
56 ········}
57
58 ········public override bool LengthAllowed(string dbType)
59 ········{
60 ············return true;
61 ········}
62
63 ········public override string DbTypeFromType(Type t, int size)
64 ········{
65 ············// CLOBs: Strings don't have a limit in Sqlite. So there is nothing to do.
66 ············return NDO.SqliteProvider.Provider.GetInternalDbType( t ).ToString();
67 ········}
68
69 public override string AutoIncrementColumn( string columnName, Type dataType, string columnType, string width, bool isPrimary)
70 ········{
71 string primary = "PRIMARY KEY ";
72 ············return $"{columnName} Integer {primary}AUTOINCREMENT";
73 ········}
74
75 ········public override bool HasSpecialAutoIncrementColumnFormat
76 ········{
77 ············get { return true; }
78 ········}
79
80 ········public override PrimaryConstraintPlacement PrimaryConstraintPlacement
81 ········{
82 ············get { return PrimaryConstraintPlacement.InColumn; }
83 ········}
84
85 ········public override string PrimaryKeyColumn(string columnName, Type dataType, string columnType, string width)
86 ········{
87 ············string coldef = columnName + " " + columnType;
88 ············if (dataType == typeof(string))
89 ················coldef += '(' + width + ')';
90 ············return coldef + " PRIMARY KEY";
91 ········}
92
93 ····}
94
95 }
96