question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select of string value bombs out

See original GitHub issue

My Data Model

public class FrameworkUserConfiguration
    {
        //used to store object in sqlite database


    public Guid FrameworkUserUid { get; set; }
    public byte[] Picture { get; set; }
    public DateTime LastUpdate { get; set; }
    public FrameworkUserDataType Type { get; set; }
    public string Description { get; set; }
    public string AudioFile { get; set; }
    public bool? RepeatAudio { get; set; }
    public bool ContainsPicture { get; set; }

    [SQLite.PrimaryKey]
    public string Identifier
    {
        get
        {
            return FrameworkUserUid.ToString() + "-" + Type;
        }
        set
        {

        }
    }
}    

  public enum FrameworkUserDataType
    {
        ActualUser,
        Admin,
        User
    }

A simple select bombs out telling me there’s no parameterless constructor (after filling the table with some random data entries)

List<string> guids = conn.Table<FrameworkUserConfiguration>().Select(x => x.Identifier).ToList();

At first glance this appears to be an issue because public IEnumerator<T> GetEnumerator () is called for T being System.String - so it then creates a dummy table mapping and once we get to var obj = Activator.CreateInstance(map.MappedType); things go wrong because System.String has no parameterless constructor.

Issue Analytics

  • State:open
  • Created 11 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
kinderrycommented, Feb 22, 2019

I had added some mthods in SQLite.cs in SQLiteCommand:

public IEnumerable<T> ExcuteSingleQuery<T>()
        {
            if (_conn.Trace)
            {
                _conn.Tracer?.Invoke("Executing Query: " + this);
            }
            var stmt = Prepare();
            try
            {
                if (SQLite3.ColumnCount(stmt) != 1)
                {
                    throw new NotSupportedException("Column count error");
                }
                while (SQLite3.Step(stmt) == SQLite3.Result.Row)
                {
                        var colType = SQLite3.ColumnType(stmt, 0);
                        var val = ReadCol(stmt, 0, colType, typeof(T));
                        yield return (T)val;
                }
            }
            finally
            {
                Finalize(stmt);
            }
        }

in SQLiteConnection:

   public List<T> SingleQuery<T>(string query, params object[] args)
        {
            var cmd = CreateCommand(query, args);
            return cmd.ExcuteSingleQuery<T>().ToList();
        }

so you can use it like this: var singlequery = conn.SingleQuery<string>("select ColumnName from TableName"); Hope for help.

1reaction
tipacommented, Jan 27, 2023

@praeclarum is there any reason the code above is not being merged? Are you waiting for a PR? It appears that many people encounter this little problem and there are also a lot of duplicate issues on this, which could also be closed with a small code addition that seems to have no negative side-effects from what I can tell.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get a value from Select-String
What i'm trying to do is get the value 49,99 in this case. I am able to get the line out of the...
Read more >
Query optimization techniques in SQL Server: tips and tricks
In this blog post we will show you step by step some tips and tricks for successful Query optimization techniques in SQL Server....
Read more >
given a string, can you access a property (in a class) that ...
I have to build an itermediate object in any case, and I'm just going to add 2 functions to that class: setValue(_ value,...
Read more >
Legacy SQL Functions and Operators | BigQuery
Most SELECT statement clauses support functions. ... GROUP BY x" returns one output record for each distinct x value, and contains a repeated...
Read more >
Defusing a Binary Bomb 1 Introduction The nefarious Dr. ...
Dr evil binary bomb. c**. A binary bomb is a program that consists of asequence of phases. If you type the correct string,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found