~dobey/ubuntu/natty/banshee/fix-and-amz

« back to all changes in this revision

Viewing changes to src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2008-07-30 12:37:28 UTC
  • mto: (1.2.3 upstream) (94.1.1 maverick)
  • mto: This revision was merged to the branch mainline in revision 70.
  • Revision ID: james.westby@ubuntu.com-20080730123728-8y78ip4btz99ri5h
Tags: upstream-1.2.0
Import upstream version 1.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
213
213
                DatabaseColumn c = member is FieldInfo
214
214
                    ? new DatabaseColumn ((FieldInfo)member, column)
215
215
                    : new DatabaseColumn ((PropertyInfo)member, column);
216
 
                
217
 
                foreach (DatabaseColumn col in columns) {
218
 
                    if (col.Name == c.Name) {
219
 
                        throw new Exception (String.Format (
220
 
                            "{0} has multiple columns named {1}",
221
 
                             TableName, c.Name)
222
 
                        );
223
 
                    }
224
 
                    if (col.Index != null && col.Index == c.Index) {
225
 
                        throw new Exception (String.Format (
226
 
                            "{0} has multiple indecies named {1}",
227
 
                            TableName, c.Name)
228
 
                        );
229
 
                    }
230
 
                }
231
 
                
232
 
                columns.Add (c);
233
 
 
234
 
                if (column.Select) {
235
 
                    select_columns.Add (c);
236
 
                }
237
 
                
238
 
                if ((c.Constraints & DatabaseColumnConstraints.PrimaryKey) > 0) {
239
 
                    if (key != null) {
240
 
                        throw new Exception (String.Format (
241
 
                            "Multiple primary keys in the {0} table", TableName)
242
 
                        );
243
 
                    }
244
 
                    key = c;
245
 
                }
 
216
                    
 
217
                AddColumn (c, column.Select);
246
218
            }
247
219
            VirtualDatabaseColumnAttribute virtual_column = attribute as VirtualDatabaseColumnAttribute;
248
220
            if (virtual_column != null) {
254
226
            }
255
227
        }
256
228
        
 
229
        protected void AddColumn (DatabaseColumn c, bool select)
 
230
        {
 
231
            foreach (DatabaseColumn col in columns) {
 
232
                if (col.Name == c.Name) {
 
233
                    throw new Exception (String.Format (
 
234
                        "{0} has multiple columns named {1}",
 
235
                         TableName, c.Name)
 
236
                    );
 
237
                }
 
238
                if (col.Index != null && col.Index == c.Index) {
 
239
                    throw new Exception (String.Format (
 
240
                        "{0} has multiple indecies named {1}",
 
241
                        TableName, c.Name)
 
242
                    );
 
243
                }
 
244
            }
 
245
            
 
246
            columns.Add (c);
 
247
 
 
248
            if (select) {
 
249
                select_columns.Add (c);
 
250
            }
 
251
            
 
252
            if ((c.Constraints & DatabaseColumnConstraints.PrimaryKey) > 0) {
 
253
                if (key != null) {
 
254
                    throw new Exception (String.Format (
 
255
                        "Multiple primary keys in the {0} table", TableName)
 
256
                    );
 
257
                }
 
258
                key = c;
 
259
            }
 
260
        }
 
261
        
257
262
        protected virtual void CreateTable ()
258
263
        {
259
264
            connection.Execute (CreateCommand);
643
648
                }
644
649
                return primary_key;
645
650
            }
 
651
            protected set { primary_key = value; }
646
652
        }
647
653
        
648
654
        private void BuildQuerySql ()
662
668
            
663
669
            StringBuilder where_builder = new StringBuilder ();
664
670
            Dictionary<string, string> tables = new Dictionary<string,string> (virtual_columns.Count + 1);
665
 
            tables.Add (TableName, null);
666
671
            bool first_virtual = true;
667
672
            foreach (VirtualDatabaseColumn column in virtual_columns) {
668
673
                if (first_virtual) {
693
698
            }
694
699
            
695
700
            StringBuilder from_builder = new StringBuilder ();
696
 
            bool first_tables = true;
 
701
            from_builder.Append (TableName);
697
702
            foreach (KeyValuePair<string, string> pair in tables) {
698
 
                if (first_tables) {
699
 
                    first_tables = false;
700
 
                } else {
701
 
                    from_builder.Append (',');
702
 
                }
 
703
                from_builder.Append (',');
703
704
                from_builder.Append (pair.Key);
704
705
            }
705
706