-
Jul 11th, 2022, 05:34 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Get the value of DefaultValue property from schema for a field in an SQLite table?
I am using SQLite (System.Data.SQLite for .NET v1.0.116.0) for an application and having trouble getting the DefaultValue property values for fields from the table schema of the SQLite database.
Here is the database structure of the Plants table from the "DB Browser for SQLite" program:
The DEFAULT property values of the "Active", "PlantType", "Sunshine", and "Water" fields are configured.
When I query the database schema for the Plant table using the following code, the DefaultValue property values for these 4 fields are not shown.
Code:
Dim strSQL As String = "Select * FROM [" & cboTables.Text & "]"
Using cmd As New SQLite.SQLiteCommand(strSQL, con)
Using rdr As SQLite.SQLiteDataReader = cmd.ExecuteReader(CommandBehavior.KeyInfo)
tbl = rdr.GetSchemaTable
End Using
End Using
For Each row As DataRow In tbl.Rows
Debug.WriteLine("{0}, {1}", row("ColumnName"), row("DefaultValue"))
Next row
The Immediate Window shows the following:
HTML Code:
RecID,
AddDate,
ModDate,
Active,
CommonName,
BotanicalName,
PlantType,
Sunshine,
Water,
Note,
Why are the DefaultValue properties that are configured in the SQLite database not returned by the query?
Last edited by Mark@SF; Jul 11th, 2022 at 05:51 AM.
-
Jul 11th, 2022, 09:04 AM
#2
Re: Get the value of DefaultValue property from schema for a field in an SQLite table
Code:
SELECT name, type, dflt_value FROM pragma_table_info('Plants') WHERE name IN ('Active', 'PlantType', 'Sunshine', 'Water')
EDIT Found something interesting:
https://github.com/Faithlife/System....eDataReader.cs
Look at line 568:
public override DataTable GetSchemaTable() => throw new NotSupportedException();
Last edited by Zvoni; Jul 11th, 2022 at 09:13 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jul 11th, 2022, 10:58 AM
#3
Thread Starter
Hyperactive Member
Re: Get the value of DefaultValue property from schema for a field in an SQLite table
Here's the solution...
Code:
strSQL = "PRAGMA table_info(Plants)"
Using cmd As New SQLite.SQLiteCommand(strSQL, con)
rdr = cmd.ExecuteReader
End Using
tblTemp.Load(rdr)
For i As Integer = 0 To tblTemp.Rows.Count - 1
Debug.WriteLine("Field #{0}: name = {1}, Type = {2}, notnull = {3}, dflt_value = {4}, pk = {5}", i, tblTemp.Rows(i)("name"), tblTemp.Rows(i)("type"), tblTemp.Rows(i)("notnull"), tblTemp.Rows(i)("dflt_value"), tblTemp.Rows(i)("pk"))
Next i
The Immediate Window shows the following:
HTML Code:
Field #0: name = RecID, Type = INTEGER, notnull = 1, dflt_value = , pk = 1
Field #1: name = AddDate, Type = CHAR(19), notnull = 1, dflt_value = , pk = 0
Field #2: name = ModDate, Type = CHAR(19), notnull = 1, dflt_value = , pk = 0
Field #3: name = Active, Type = BOOLEAN, notnull = 0, dflt_value = TRUE, pk = 0
Field #4: name = CommonName, Type = VARCHAR(25), notnull = 1, dflt_value = , pk = 0
Field #5: name = BotanicalName, Type = VARCHAR(25), notnull = 1, dflt_value = , pk = 0
Field #6: name = PlantType, Type = INTEGER, notnull = 0, dflt_value = 3, pk = 0
Field #7: name = Sunshine, Type = INTEGER, notnull = 0, dflt_value = 3, pk = 0
Field #8: name = Water, Type = INTEGER, notnull = 0, dflt_value = 3, pk = 0
Field #9: name = Note, Type = VARCHAR(65536), notnull = 0, dflt_value = , pk = 0
The dflt_value property show the DEFAULT values that were configured for the database table.
-
Sep 28th, 2022, 05:35 AM
#4
Re: [RESOLVED] Get the value of DefaultValue property from schema for a field in an S
Would you believe it, that i needed this myself right now?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|