I need to update one field only in my table :
static Future<void> updateType(Statement statement, String type) async {
await db.update('StatementTABLE',
{'type' : '?'},
where: "id = ?",
whereArgs: [type,statement.id]);
}
But I have this error message :
"DatabaseException(Too many bind arguments. 3 arguments were provided
but the statement needs 2 arguments.) sql 'UPDATE StatementTABLE SET
type = ? WHERE id = ?' args [?, Sortie,
56fcb6b0-a283-11eb-a4d4-1ffc954983be]}"
I do not understand as I have well 2 arguments and not 3 ..
whereArgs is only to replace values in whee clause. type should be in the map :
await db.update('StatementTABLE',
{'type' : type},
where: "id = ?",
whereArgs: [statement.id]);
Related
LINQ to Entities does not recognize the System.String ToString(System.String) method, and this method cannot be translated into a store expression.
List<ModelName> List = await (
linq query write here
select new ModelName
{
Column Name,
chkIN = VD.CheckIN.ToString(),
}).ToListAsync();
List<ModelName> List = await (
linq query write here
select new ModelName
{
Column Names,
checkin = VD.CheckIN.Value
}).ToListAsync();
List.ForEach(x => x.chkIN = x.checkin.HasValue ? DateTime.Today.Add(x.checkin.Value).ToString("hh:mm tt") : "");
return List;
I want to return Distinct records from a table in SQLITE flutter by giving some condition such as return All the distinct records where ID = x (where x will be taken by the user).
How can I achieve this?
Working with the SQFlite package you can use a query or a rawQuery to perform that, in both cases you need to pass the where arguments as an array, and for the distinct operator you can do it as follows:
/// [GET] Get all the data by date using a query
getData(String date) async {
final db = await database;
final response = await db.query(
"TableExample",
distinct: true,
orderBy: 'id',
where: 'date = ?',
whereArgs: [date],
);
//...
}
/// [GET] Get all the data by date using a rawQuery
getDailyPollResponsesPerRangeDate(String date) async {
final db = await database;
final response = await db.rawQuery(
"SELECT DISTINCT TableExample.id, TableExample.date "
"FROM TableExample "
"WHERE TableExample.date == ? "
"ORDER BY TableExample.date DESC",
[date],
);
//...
}
I have a problem in my code that occurs error in lunching in database_helper.dart
database_helper.dart is one file in Sqlite storing data learning project and i faced this issue ,
i tried many solutions like uninstall app and install it again
can any one help me ?
======
class DataBaseHelper {
static Database _db ;
final String userT = 'userT' ;
final String columnId = 'id' ;
final String columnUserName = 'username' ;
final String columnPassword = 'password' ;
final String columnAge = 'age' ;
final String columnCity = 'city' ;
=========
Future<Database> get dbase async {
if(_db != null) {
return _db ;
}
_db = await intDB();
return _db ;
}
=================
intDB() async {
Directory docDirectory = await getApplicationDocumentsDirectory() ;
String path = join(docDirectory.path , 'myDB.db') ;
var myOwnDB = await openDatabase(path , version: 1 , onCreate: _onCreate);
return myOwnDB ;
}
=========================
void _onCreate(Database db , int newVersion) async {
var sql = 'CREATE TABLE $userT ($columnId INTEGER PRIMARY KEY UNIQUE ,'
' $columnUserName TEXT , $columnPassword TEXT , $columnCity TEXT , $columnAge INTEGER ' ;
await db.execute(sql) ;
}
error log:
E/SQLiteLog(14607): (1) near "INTEGER": syntax error
I/flutter (14607): error DatabaseException(near "INTEGER": syntax error (code 1): , while compiling: CREATE TABLE userT (id INTEGER PRIMARY KEY UNIQUE , username TEXT , password TEXT , city TEXT , age INTEGER) during oenter code herepen, closing...
E/flutter (14607): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: DatabaseException(near "INTEGER": syntax error (code 1): , while compiling: CREATE TABLE userT (id INTEGER PRIMARY KEY UNIQUE , username TEXT , password TEXT , city TEXT , age INTEGER)
Syntax error. you forgot to put ) at the end of line
$columnAge INTEGER )
You can check your sqllite code in https://sqliteonline.com/
CREATE TABLE userT (columnId INTEGER PRIMARY KEY UNIQUE ,
columnUserName TEXT , columnPassword TEXT , columnCity TEXT , columnAge INTEGER)
after put ) . it works fine.
Edit : Second question of Insert Into statement you mentioned in comments
The syntax error of Insert Into statement is column "userCity" does not exist.
In the question you provided, when Create table you use the name columnCity = 'city'. so you sholud change the name to "city".
Try removing UNIQUE
They have not included that word in any of the samples, so maybe it has not been implemented.
I created a local string type attribute on a type in Windchill. I'm trying to fetch the value of that attribute using QuerySpec but it's throwing the following exception:
2019-04-16 20:53:05,092 INFO [ajp-nio-127.0.0.1-8011-exec-5]
wt.system.err - wt.query.QueryException: Attribute
"ptc_str_89typeInfoLCSProduct" is not a member of class "class
com.lcs.wc.product.LCSSKU" 2019-04-16 20:53:05,092 INFO
[ajp-nio-127.0.0.1-8011-exec-5] wt.system.err - Nested exception is:
Attribute "ptc_str_89typeInfoLCSProduct" is not a member of class
"class com.lcs.wc.produ
Following is my code:
String colorwayId = product.getFlexType().getAttribute("colorwayID")
.getColumnName();
QuerySpec qs = new QuerySpec();
int classIndex = qs.appendClassList(typeDefRef.getKey().getClass(), false);
ClassAttribute ca = new ClassAttribute(
typeDefRef.getKey().getClass(), colorwayId);
qs.appendSelect(ca, new int[] { classIndex }, false);
QueryResult qr = PersistenceHelper.manager.find(qs);
Normally ClassAttribute gets attribute name instead of column name (database column).
Your ptc_str_89typeInfoLCSProduct column is in fact typeInfoLCSProduct.ptc_str_89 like State is state.state.
To get this information, you need to use PersistableAdapter like this:
public String getAttributeColumnName(String softType, String logicalAttributeName) throws WTException {
PersistableAdapter persistableAdapter = new PersistableAdapter(softType, Locale.getDefault(), Operation.DISPLAY);
persistableAdapter.load(logicalAttributeName);
AttributeTypeSummary attributeDescriptor = persistableAdapter.getAttributeDescriptor(logicalAttributeName);
return null != attributeDescriptor ? (String) attributeDescriptor.get(AttributeTypeSummary.DESCRIPTION) : null;
}
And then use this method:
String colorwayId = getAttributeColumnName("your_softtype", "attribute_name_from_type_manager");
These are my model classes
I have three tables
But when I update my model, the PurchaseReturnDetail table is not there in the model, and it creates a one-to-many relationship between PurchaseReturn and PurchaseDetail.
I'm using repository pattern and I don't know how to insert transactions in PurchaseReturnDetail table.
Following is my code to insert transaction. but it gives exception
Message = "An entity object cannot be referenced by multiple instances of IEntityChangeTracker."
public async Task<Response> SaveAsync(PurchaseReturn purchaseReturn, List<string> serialNoList)
{
PurchaseReturnRepository rep = new PurchaseReturnRepository();
decimal totalRate = 0;
foreach (var serialNo in serialNoList)
{
var purchaseDetail = await PurchaseService.Instance.GetSinglePurchasedItemDetailAsync(serialNo);
purchaseReturn.PurchaseDetails.Add(purchaseDetail);
//Calculating total rate to update supplier balance
totalRate += purchaseDetail.Rate;
}
var response = await rep.AddAsync(purchaseReturn);
if (response.Success)
{
//Updating Supplier Balance
response = await SupplierService.Instance.UpdataBalanceAsync(purchaseReturn.SupplierId, totalRate, false);
response.Msg = "Items has beed returned and stock is updated";
}
return response;
}
NOTE : I'm using database first approach