I want to know the difference between following two statements related to datasets in delphi.
dsMyDataSet.ParamByName('ID').AsInteger := 1122; //If ID is integer
dsMyDataSet.ParamByName('ID').AsString := '1122'; //If ID is string
and
dsMyDataSet.ParamByName('ID').Value := 1122; //ID is string or integer
Do these statements carry same meaning? Does "value" implicitly converts integer into string?
The TParam.AsInteger property, for instance, set the value and the data type of the parameter. TParam.Value does the same, but TParam will decide which type will be mapped to the value inside the Variant and not always it´s the data type you would like.
I advise you to set values by using the AsXXX properties only, since you will be in control of the parameter's data type, what can save you from having parameter binding errors.
So, answering your final question: no, the values won´t be converted to the right data type, you have to set the data type by selecting the right property to assign the value.
Related
I want to know the default values of data-types in Dart.
Integer,Double,String,Dynamic and Boolean.
The default value for all types in Dart are null if nothing else is specified when declaring the variable. This includes int, double, String and so on.
Uninitialized variables that have a nullable type have an initial value of null. (If you haven’t opted into null safety, then every variable has a nullable type.) Even variables with numeric types are initially null, because numbers—like everything else in Dart—are objects.
https://dart.dev/guides/language/language-tour#default-value
Is there a noticeable difference between the two?
var example = ["some","content",11,45,true];
List example = ["some","content",11,45,true];
With var example the type (static and runtime) for example will be inferred from the assigned value ["some","content",11,45,true] which will be List (or actually List<dynamic>)
With List example the type will not be inferred but the explicitely provided type List (or actually List<dynamic> if no generic type is provided) will be used instead.
For var example = ["some","content","11","45","true"]; the inferred type would be List<String>.
As far as I know and as simple as I can be;
List is a data type just like some other built-in types in Dart such as String, int and bool. When you initialize a variable using List, the assigned value must be of List type. i.e. You cannot do this
List example = "sometext";
because you're trying to assign a String value to a List variable or object here.
Whereas, var is a way to declare a variable without specifying its type. For var will accept all kind of data types.
Is there a noticeable difference between the two?
var example = ["some","content",11,45,true];
List example = ["some","content",11,45,true];
Both the methods of declaration have same effect unless you expect to assign a value to example with type(s) other than List during it's lifetime. i.e If you're looking to assign an int or double or string or whatever value to example in future use the first method else you can use any one of them.
What value does val, which is of string type, get when the column named fieldName is null for the selected row? Here myQry is a database query.
val := myQry.FieldByName('fieldName').AsString
Here column fieldName does exist in the table, but for the selected row/record, the value is null. I have looked here. It was informative, but didn't have the information I needed I am afraid. I also looked at this but that didn't help much either.
You can test this yourself simply by calling
MyDataSet.FieldByName('MyField').Clear
That sets MyField to Null and, after that, calling AsString on it returns an empty (zero-length) string.
The GetAsString method of TField descendants typically contain code like this:
function TIntegerField.GetAsString: string;
var
L: Longint;
begin
if GetValue(L) then Str(L, Result) else Result := '';
end;
Here, GetValue succeeds if it is possible to retrieve a value from the current record buffer. If it fails, the field is taken to contain Null.
Typically, depending on the actual type of field, the empty string is returned. But this does depend on the implementation of the TField descendant, and you have given no indication of what that is.
In order to distinguish between null and an empty string, use the IsNull property of the field.
AsString returns the String value for the field if it has value or the empty string if it does not have the value.
AsString does not use DisplayText or other things.
It is absolutely safe to call AsString on NULL value fields.
I have a table in my DB. In that table, I have a value stored (it's a date, in milliseconds): "1424386800000", in a column named "fechainicio".
I have downloaded SQLite browser in my Mac to actually check that the value is stored, and its correct, and it is.
Later, in my code, I retrieve that value using this:
var fechaInicio:Int64=Int64(results!.intForColumn("fechainicio"))
When I do this, I am receiving the value "-1542342272".
Why is the value retrieved incorrectly?
I have tried also
var fechaInicio:Int64=results!.intForColumn("fechainicio").toIntMax()
and
var fechaInicio=results!.intForColumn("fechainicio")
Isn't Int64 the correct type to retrieve a long value from a database?
The int type from (Objective-)C is a 32-bit integer type (and mapped to Int32 in Swift). This means that the
- (int)intForColumn:(NSString*)columnName;
method from FMDB can return only 32-but values. This method ultimately calls the SQLite function
int sqlite3_column_int(sqlite3_stmt*, int iCol);
which returns the lower 32-bit of the value, without any overflow check.
The proper solution is to use
- (long)longForColumn:(NSString*)columnName;
instead which returns Int64 in Swift.
I have the following enum in Delphi:
type TChangingDataSetState=(Inserting=1,Editing,Deleting)
......
var
ChangingDSSsate:TChangingDataSetState;
In BeforePost event I check if the dataset in Insert mode then I
ChangingDSState:=Inserting
else
ChagingDSState:=Editing
Let's say the dataset is in edit mode, it means my ChangingDSState var will get evuluated to 2(Editing). Now I want to know how I can then use that number to pass it as an argument to a procedure
I assume you want the ordinal value rather than the enumerated value. You get that with ord().
So, ord(ChagingDSState) is an integer expression with a value of 2 when ChagingDSState equals Editing.