Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Array List - DebugLog Content

Discussion in 'Scripting' started by AndreaTonin, Aug 31, 2015.

  1. AndreaTonin

    AndreaTonin

    Joined:
    Apr 6, 2014
    Posts:
    9
    Hi all,
    I want render inside a UI Text an Array List content got from a SQLite DB, but the Debog.Log is: System.Collections.ArrayList, System.Collections.ArrayList etc...
    I am missing some code?
    My code is:
    Code (JavaScript):
    1.  
    2. // #####################################################################
    3. // READ FULL TABLE #########################################################
    4. // #####################################################################
    5. // This returns a 2 dimensional ArrayList with all the
    6.     //  data from the table requested
    7. function ReadFullTable(tableName : String) {
    8.         var query : String;
    9.         query = "SELECT * FROM " + tableName;
    10.         dbcmd = dbcon.CreateCommand();
    11.         dbcmd.CommandText = query;
    12.         reader = dbcmd.ExecuteReader();
    13.         var readArray = new ArrayList();
    14.         while(reader.Read()) {
    15.             var lineArray = new ArrayList();
    16.             for (var i:int = 0; i < reader.FieldCount; i++)
    17.                 lineArray.Add(reader.GetValue(i)); // This reads the entries in a row
    18.             readArray.Add(lineArray); // This makes an array of all the rows
    19.         }
    20.         return readArray; // return matches
    21.     }// END ReadFullTable()
    22.    
    23. function ShowDatabase (){
    24.         databaseData = ReadFullTable("friends");
    25.         Debug.Log (Array(databaseData).ToString());
    26.         textDbContent.text = Array(databaseData).ToString();
    27. }// END ShowDatabase ()
    28.  
    Thanks in advance
    Andrea
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Any reason why you are using an array list? The class has generally been deprecated in favour of generic lists.
     
  3. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    974
    What do you think this code should be doing?

    Code (JavaScript):
    1. Debug.Log (Array(databaseData).ToString());
    The way I read it, you are calling a method called Array and passing an ArrayList as the argument. Then calling ToString() on whatever comes back and sending all of that to Debug.Log.

    I could be wrong about this but I don't know what the Array method could be other than the constructor of an Array, which expects an int instead of an ArrayList.

    Second, calling ToString() on a class returns the fully qualified name (FQN) of the class unless it has overridden the default ToString() behavior. Assuming Array(databaseData) returns an ArrayList, calling ToString() will probably just return the class's FQN: System.Collections.ArrayList. If you want to print out the contents of the array, this will likely work for you: http://stackoverflow.com/questions/5050507/question-regarding-cs-list-tostring
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you want to print the contents of a list, loop through the list and print each entry.

    --Eric
     
    Kiwasi likes this.