Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C# - SQLite

Name: Anonymous 2008-05-15 11:39

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SQLite;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            SQLiteConnection.CreateFile("failure.db");
            SQLiteConnection.CompressFile("failure.db");
            SQLiteConnection DB = new SQLiteConnection("Data source=failure.db");
            DB.Open();

            using (SQLiteCommand DBc = DB.CreateCommand())
            {
                DBc.CommandText = "CREATE TABLE 'records' (" +
                    "'id' text, " +
                    "'name' text, " +
                    "'address' text, " +
                    "'phone' text)";
                DBc.ExecuteNonQuery();
            }
            using (SQLiteCommand DBc = DB.CreateCommand())
            {
                DBc.CommandText = "INSERT INTO 'records' " +
                    "(id, name, address, phone) VALUES " +
                    "('js', 'john', 'lolwut', '92837412')";
                DBc.ExecuteNonQuery();
            }
            using (SQLiteCommand DBc = DB.CreateCommand())
            {
                DBc.CommandText = "UPDATE 'records' SET ? = ? WHERE id = ?";
                SQLiteParameter prm1 = DBc.CreateParameter();
                SQLiteParameter prm2 = DBc.CreateParameter();
                SQLiteParameter prm3 = DBc.CreateParameter();
                DBc.Parameters.Add(prm1);
                DBc.Parameters.Add(prm2);
                DBc.Parameters.Add(prm3);
                prm1.Value = "address";
                prm2.Value = "dickbutt";
                prm3.Value = "js";
                DBc.ExecuteNonQuery();
            }
            using (SQLiteCommand DBc = DB.CreateCommand())
            {
                DBc.CommandText = "SELECT * FROM 'records'";
                using (SQLiteDataReader DBr = DBc.ExecuteReader())
                {
                    DBr.Read();
                    Console.WriteLine("  ID> " + DBr.GetString(0));
                    Console.WriteLine("NAME> " + DBr.GetString(1));
                    Console.WriteLine("ADDR> " + DBr.GetString(2));
                    Console.WriteLine(" TEL> " + DBr.GetString(3));
                }
            }
            Console.Read();
        }
    }
}

It crashes when it executes the update query. Error message reads "SQLite error near "?": syntax error".
It's worth to notice that it works perfectly if I comment out prm1 and enter the column name directly into the CommandText.

What am I doing wrong?

Name: Anonymous 2008-05-15 11:46

i dunno lol

Name: Anonymous 2008-05-15 11:56

Yeah, I noticed this too!

I guess it doesn't support using DbParameters as column names.

Name: Anonymous 2008-05-15 12:04

>>3

I hope that isn't so. If that's really true, then I've got a lot of rewriting to do.

Name: Anonymous 2008-05-15 12:04

>>3
Why would it?

Name: Anonymous 2008-05-15 12:05

>>5
Why on earth shouldn't it?

Name: Anonymous 2008-05-15 12:09

>>4
The thing that will stop you from using a tablename as an argument to a
parameterized query is that (the) front-ends (I am familiar with) don't
allow table names to be parameterized, as you've demonstrated.

The main points of parameterization are

1) To let the driver handle the creation of syntactically correct SQL
(thereby avoiding , e.g. SQL injection attacks) and

2) To allow the driver to get the back-end to optimize the query by
developing an execution plan into which the parameters can ve inserted
at run time, avoiding repeated recompilation of the same query. It's
this that stops most backends from allowing table names, since the
optimizations depend upon the table's characteristics and contents.

If you absolutely must dynamically insert a table or column
name, the only viable method is to insert them into the query string
yourself (using a sprintf-like function). Naturally this sacrifices
the securities of parameterization, so you won't be able to safely
pass user-generated data in there. Consider rethinking your design.

Name: Anonymous 2008-05-15 12:09

>>5
i dunno lol

Name: Anonymous 2008-05-15 12:10

>>2,8
back to /b/, please

Name: Anonymous 2008-05-15 12:11

>>7
That explains it. Thank you for your time (and good explanation).

Name: Anonymous 2008-05-15 12:13

JESUS WHAT ARE YOU RETARDED
NO SQL SUPPORTS NONVALUE PLACEHOLDERS
YOU CAN'T JUST CHANGE THE EXECUTION PATH OF A QUERY FOR EVERY PARAMETER SET

Name: 3 2008-05-15 12:24

>>7
Yeah, I figured it would be the second, since (SQLite at least) compiles queries into a assembly-style language.

Name: Anonymous 2008-05-15 12:24

>>11
RAAGGGGGGGEEEEEEEEEEE

Name: Anonymous 2008-05-15 12:41

>>11
I have never been using any form of SQL before today, so how would I know that?

Name: Anonymous 2008-05-15 12:48

>>7 is correct. Parameters can only be specified for literal data, not schema or commands. This is common to all DBMS not just SQLite.

Name: Anonymous 2009-03-06 8:14

More than one guy   is following a   meme I posted   in that gamedev   thread back in   my day yhbt.

Name: Trollbot9000 2009-07-01 8:44


prm1 and enter the.

Name: MBT Shoes Sale 2010-05-20 10:24


The Houston Rockets Discount Air Max did not win the draft lottery, an outcome as surprising as traffic gridlock on the city's freeways during rush hour.
The team carried a 98 percent Nike Air Max chance of picking 14th to Secaucus. Aaron Brooks' Nike Shox Series spresence could not inspire a miracle.
The Rockets' Air Jordans Shoes primary offseason target is clearer than a new pane of glass. The team's followers know. General Manager Daryl Morey Shox R4 2009 could stand to work on his poker face.
Chris Bosh Nike Air Max 90 should know what to expect at midnight on July 1—Morey's smiling face at his doorstep with a plea and an offer.
How might a lottery selection, albeit the last one, affect the Rockets' chances to land the coveted forward?
The Toronto Raptors Air Max 95 Womens, Bosh's current squad, will pick one slot higher at 13th.
After Wall, Turner, DeMarcus Cousins, Derrick Favors, and Wesley Johnson Nike Air Max 2009, the order of the rest is anyone's guess. All but two of the players in the top 20 of most mock drafts are forwards are centers.
Most think Turner will become a forward, as he bulks up his Air Max 2003 Mens body and bolsters his confidence on the NBA Air Classic BW level.
Morey could package the player plus the draft picks acquired from the New York Knicks Vibram FiveFingers KSO in the Tracy McGrady deal in a sign-and-trade for Bosh.
The last time the franchise picked in the lottery, the brain trust opted to trade the rights to Rudy Gay for defensive specialist Shane Battier.Before that, the team snagged Yao Ming Air Max Shoes.
http://www.mbtflying.com/

Name: Anonymous 2010-12-17 1:33

Xarn is a bad boyfriend

Name: barbour mens classic duffle 2011-12-01 22:41

There are many brands of <a href="http://www.barbourjackets-uk.org/"><strong>barbour fusilier</strong></a> in the market today. Each of the brand promises to bring out something new to the customers.

Name: oakley m frame 2012-02-25 21:19

thank you for  your share  i think it's useful to the need  one  i like ithttp://www.oakleymframe.com/

Name: oakley m frame 2012-02-25 21:33

thank you for  your share  i think it's useful to the need  one  i like it<a href="http://www.oakleymframe.com/">Discount oakley sunglasses</a>

Name: Sgt.Kabukiman蝳 2012-05-23 5:44

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List