diff options
author | Sean Dague | 2007-09-28 11:11:36 +0000 |
---|---|---|
committer | Sean Dague | 2007-09-28 11:11:36 +0000 |
commit | ebfb05758389a6cc2e535cee4cf723a1fd3c763f (patch) | |
tree | d8fcb97e9a58d01bfd4a0ff4376a75aa41c5d95c | |
parent | implement getInventoryItem and getInventoryFolder (not (diff) | |
download | opensim-SC-ebfb05758389a6cc2e535cee4cf723a1fd3c763f.zip opensim-SC-ebfb05758389a6cc2e535cee4cf723a1fd3c763f.tar.gz opensim-SC-ebfb05758389a6cc2e535cee4cf723a1fd3c763f.tar.bz2 opensim-SC-ebfb05758389a6cc2e535cee4cf723a1fd3c763f.tar.xz |
negative code checkin. All these functions are in the base
class which we get for free now.
-rw-r--r-- | OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs | 163 |
1 files changed, 1 insertions, 162 deletions
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs b/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs index 4639e09..ba6038c 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs | |||
@@ -15,7 +15,7 @@ using Mono.Data.SqliteClient; | |||
15 | namespace OpenSim.Framework.Data.SQLite | 15 | namespace OpenSim.Framework.Data.SQLite |
16 | { | 16 | { |
17 | 17 | ||
18 | public class SQLiteInventoryStore : IInventoryData | 18 | public class SQLiteInventoryStore : SQLiteBase, IInventoryData |
19 | { | 19 | { |
20 | private const string invItemsSelect = "select * from inventoryitems"; | 20 | private const string invItemsSelect = "select * from inventoryitems"; |
21 | private const string invFoldersSelect = "select * from inventoryfolders"; | 21 | private const string invFoldersSelect = "select * from inventoryfolders"; |
@@ -441,128 +441,6 @@ namespace OpenSim.Framework.Data.SQLite | |||
441 | 441 | ||
442 | /*********************************************************************** | 442 | /*********************************************************************** |
443 | * | 443 | * |
444 | * SQL Statement Creation Functions | ||
445 | * | ||
446 | * These functions create SQL statements for update, insert, and create. | ||
447 | * They can probably be factored later to have a db independant | ||
448 | * portion and a db specific portion | ||
449 | * | ||
450 | **********************************************************************/ | ||
451 | |||
452 | private SqliteCommand createInsertCommand(string table, DataTable dt) | ||
453 | { | ||
454 | /** | ||
455 | * This is subtle enough to deserve some commentary. | ||
456 | * Instead of doing *lots* and *lots of hardcoded strings | ||
457 | * for database definitions we'll use the fact that | ||
458 | * realistically all insert statements look like "insert | ||
459 | * into A(b, c) values(:b, :c) on the parameterized query | ||
460 | * front. If we just have a list of b, c, etc... we can | ||
461 | * generate these strings instead of typing them out. | ||
462 | */ | ||
463 | string[] cols = new string[dt.Columns.Count]; | ||
464 | for (int i = 0; i < dt.Columns.Count; i++) { | ||
465 | DataColumn col = dt.Columns[i]; | ||
466 | cols[i] = col.ColumnName; | ||
467 | } | ||
468 | |||
469 | string sql = "insert into " + table + "("; | ||
470 | sql += String.Join(", ", cols); | ||
471 | // important, the first ':' needs to be here, the rest get added in the join | ||
472 | sql += ") values (:"; | ||
473 | sql += String.Join(", :", cols); | ||
474 | sql += ")"; | ||
475 | SqliteCommand cmd = new SqliteCommand(sql); | ||
476 | |||
477 | // this provides the binding for all our parameters, so | ||
478 | // much less code than it used to be | ||
479 | foreach (DataColumn col in dt.Columns) | ||
480 | { | ||
481 | cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); | ||
482 | } | ||
483 | return cmd; | ||
484 | } | ||
485 | |||
486 | private SqliteCommand createUpdateCommand(string table, string pk, DataTable dt) | ||
487 | { | ||
488 | string sql = "update " + table + " set "; | ||
489 | string subsql = ""; | ||
490 | foreach (DataColumn col in dt.Columns) | ||
491 | { | ||
492 | if (subsql.Length > 0) | ||
493 | { // a map function would rock so much here | ||
494 | subsql += ", "; | ||
495 | } | ||
496 | subsql += col.ColumnName + "= :" + col.ColumnName; | ||
497 | } | ||
498 | sql += subsql; | ||
499 | sql += " where " + pk; | ||
500 | SqliteCommand cmd = new SqliteCommand(sql); | ||
501 | |||
502 | // this provides the binding for all our parameters, so | ||
503 | // much less code than it used to be | ||
504 | |||
505 | foreach (DataColumn col in dt.Columns) | ||
506 | { | ||
507 | cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); | ||
508 | } | ||
509 | return cmd; | ||
510 | } | ||
511 | |||
512 | |||
513 | private string defineTable(DataTable dt) | ||
514 | { | ||
515 | string sql = "create table " + dt.TableName + "("; | ||
516 | string subsql = ""; | ||
517 | foreach (DataColumn col in dt.Columns) | ||
518 | { | ||
519 | if (subsql.Length > 0) | ||
520 | { // a map function would rock so much here | ||
521 | subsql += ",\n"; | ||
522 | } | ||
523 | subsql += col.ColumnName + " " + sqliteType(col.DataType); | ||
524 | if(col == dt.PrimaryKey[0]) | ||
525 | { | ||
526 | subsql += " primary key"; | ||
527 | } | ||
528 | } | ||
529 | sql += subsql; | ||
530 | sql += ")"; | ||
531 | return sql; | ||
532 | } | ||
533 | |||
534 | /*********************************************************************** | ||
535 | * | ||
536 | * Database Binding functions | ||
537 | * | ||
538 | * These will be db specific due to typing, and minor differences | ||
539 | * in databases. | ||
540 | * | ||
541 | **********************************************************************/ | ||
542 | |||
543 | ///<summary> | ||
544 | /// This is a convenience function that collapses 5 repetitive | ||
545 | /// lines for defining SqliteParameters to 2 parameters: | ||
546 | /// column name and database type. | ||
547 | /// | ||
548 | /// It assumes certain conventions like :param as the param | ||
549 | /// name to replace in parametrized queries, and that source | ||
550 | /// version is always current version, both of which are fine | ||
551 | /// for us. | ||
552 | ///</summary> | ||
553 | ///<returns>a built sqlite parameter</returns> | ||
554 | private SqliteParameter createSqliteParameter(string name, System.Type type) | ||
555 | { | ||
556 | SqliteParameter param = new SqliteParameter(); | ||
557 | param.ParameterName = ":" + name; | ||
558 | param.DbType = dbtypeFromType(type); | ||
559 | param.SourceColumn = name; | ||
560 | param.SourceVersion = DataRowVersion.Current; | ||
561 | return param; | ||
562 | } | ||
563 | |||
564 | /*********************************************************************** | ||
565 | * | ||
566 | * Test and Initialization code | 444 | * Test and Initialization code |
567 | * | 445 | * |
568 | **********************************************************************/ | 446 | **********************************************************************/ |
@@ -612,45 +490,6 @@ namespace OpenSim.Framework.Data.SQLite | |||
612 | } | 490 | } |
613 | return true; | 491 | return true; |
614 | } | 492 | } |
615 | |||
616 | |||
617 | /*********************************************************************** | ||
618 | * | ||
619 | * Type conversion functions | ||
620 | * | ||
621 | **********************************************************************/ | ||
622 | |||
623 | private DbType dbtypeFromType(Type type) | ||
624 | { | ||
625 | if (type == typeof(System.String)) { | ||
626 | return DbType.String; | ||
627 | } else if (type == typeof(System.Int32)) { | ||
628 | return DbType.Int32; | ||
629 | } else if (type == typeof(System.Double)) { | ||
630 | return DbType.Double; | ||
631 | } else if (type == typeof(System.Byte[])) { | ||
632 | return DbType.Binary; | ||
633 | } else { | ||
634 | return DbType.String; | ||
635 | } | ||
636 | } | ||
637 | |||
638 | // this is something we'll need to implement for each db | ||
639 | // slightly differently. | ||
640 | private string sqliteType(Type type) | ||
641 | { | ||
642 | if (type == typeof(System.String)) { | ||
643 | return "varchar(255)"; | ||
644 | } else if (type == typeof(System.Int32)) { | ||
645 | return "integer"; | ||
646 | } else if (type == typeof(System.Double)) { | ||
647 | return "float"; | ||
648 | } else if (type == typeof(System.Byte[])) { | ||
649 | return "blob"; | ||
650 | } else { | ||
651 | return "string"; | ||
652 | } | ||
653 | } | ||
654 | } | 493 | } |
655 | } | 494 | } |
656 | 495 | ||