Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6123805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:03:34+00:00 2026-05-23T16:03:34+00:00

I am having an issue using SQLiteParameters and the LIKE operator in a SQLite

  • 0

I am having an issue using SQLiteParameters and the LIKE operator in a SQLite query. Here is a snippet of code, and I apologize if I don’t have enough code here. If that is the case, I can easily post more.

Poor Performance:

using (OdysseyDataContext entities = new OdysseyDataContext())
{
    var results = entities.SearchResults.SqlQuery(
        "SELECT * FROM SearchResults WHERE ContactName LIKE @ContactName",
        new SQLiteParameter("@ContactName", "test")
    );
}

Great Performance:

using (OdysseyDataContext entities = new OdysseyDataContext())
{
    var results = entities.SearchResults.SqlQuery(
        string.Format(
            "SELECT * FROM SearchResults WHERE ContactName LIKE '{0}'",
            "test"
        )
    );
}

Other important code:

public class OdysseyDataContext : DbContext
{
    public DbSet<SearchResult> SearchResults { get; set; }
}

public class SearchResult
{
    [Key]
    public Guid Id { get; set; }
    public string ContactName { get; set; }
}

The first example takes 700 ms to execute, which my supervisor finds unacceptable. The second example takes 7 ms to execute. Why the difference? Is there something I am doing completely wrong to earn me newbie status?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:03:35+00:00Added an answer on May 23, 2026 at 4:03 pm

    So, I think I may have narrowed it down to an issue with System.Data.SQLite. I tried the following code in C++:

    #include "sqlite3.h"
    #include <stdio.h>
    
    void xProfile(void* pArg, const char* query, sqlite3_uint64 pTimeTaken)
    {
        printf("%s\n", query);
        printf("%I64d ms\n", pTimeTaken / 1000000);
    }
    
    void PoorPerformance();
    void GoodPerformance();
    
    int main()
    {
        printf("Poor Performance:\n");
        PoorPerformance();
    
        printf("Good Performance:\n");
        GoodPerformance();
    
        return 0;
    }
    
    void PoorPerformance()
    {
        int rc;
        int rowCount = 0;
    
        sqlite3 *db;
        if (sqlite3_open("<<File Here>>", &db))
        {
            printf("Could not open the database.");
            return;
        }
    
        sqlite3_profile(db, &xProfile, NULL);
    
        sqlite3_stmt *statement;
        if (!sqlite3_prepare_v2(db, "SELECT * FROM SearchResults WHERE ContactName LIKE @ContactName;", -1, &statement, 0))
        {
            int result = 0;
            int parameterIndex = sqlite3_bind_parameter_index(statement, "@ContactName");
            sqlite3_bind_text(statement, 1, "test", -1, NULL);
            while (result != SQLITE_DONE)
            {
                result = sqlite3_step(statement);
    
                if (result == SQLITE_ROW)
                {
                    rowCount++;
                }
            }
    
            sqlite3_finalize(statement);
        }
    
        printf("%d rows\n", rowCount);
    
        sqlite3_close(db);
    }
    
    void GoodPerformance()
    {
        int rc;
        int rowCount = 0;
    
        sqlite3 *db;
        if (sqlite3_open("<<File Here>>", &db))
        {
            printf("Could not open the database.");
            return;
        }
    
        sqlite3_profile(db, &xProfile, NULL);
    
        sqlite3_stmt *statement;
        if (!sqlite3_prepare_v2(db, "SELECT * FROM SearchResults WHERE ContactName LIKE 'test';", -1, &statement, 0))
        {
            int result = 0;
    
            while (result != SQLITE_DONE)
            {
                result = sqlite3_step(statement);
    
                if (result == SQLITE_ROW)
                {
                    rowCount++;
                }
            }
    
            sqlite3_finalize(statement);
        }
    
        printf("%d rows\n", rowCount);
    
        sqlite3_close(db);
    }
    

    Both the PoorPerformance and GoodPerformance functions yielded 1 ms with 11 rows. Is there something different between what I did and what should have been done by System.Data.SQLite? Hopefully this is just something I can report as a bug with System.Data.SQLite and perhaps apply my own fix.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I believe I am having a memory issue using numpy arrays. The following code
I'm having an issue with the following code: private void DataPortal_Fetch(TaskCriteria criteria) { using
having an issue using a NSMutableArray; In my implementation file applicationDidFinishLaunching method I have
I’m having an issue using SqlBulkCopy when nullable columns are involved. It sounds like
I am having an issue using the maxrows property of tilelist. My code looks
I'm having an issue while using group-adjacent. Below a simplified XML snippet : <Paras>
Have been having an issue sine using the HABTM relationship in models instead of
I am having an issue using BinaryFormatter.Serialize. I have this generic extension method to
i'm having an issue using C# inserting multiple rows into a MySQL database, have
I am having a small issue using the classic WebLogin snippet (Not WebLoginPE) in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.