Float Datatype is not defined in mongoose-express database schema - express

I am using express with mongoose in mongodB's local type (mongodB compass). I was defining float type of datatype while creating a schema in mongoose, but it is showing me an error [here is the error] (https://i.stack.imgur.com/WFAGM.png)
what if we have to define float type value like 10000000.25 also what another datatype we can use in place of float?
Note-I tried both float and Float but none is working.

Related

Parametrizing blob types using gnatcoll.sql

I am using the Ada library gnatcoll.sql to create parametrizable SQL queries.
While I am able to create Integer parameters for type SQL_Field_Integer using the function:
function Integer_Param (Index : Positive) return Integer_Fields.Field'Class
renames Integer_Fields.Param;
As well as for the following types using their respective functions:
SQL_Field_Bigint, SQL_Field_Text, SQL_Field_Boolean, SQL_Field_Float, SQL_Field_Long_Float, SQL_Field_Money, SQL_Field_Time, SQL_Field_Date
I am not able to parametrize Blob fields, I don't find those type mappings nor any service except the postgresql/sqlite bindings at low-level.
How can I parametrize blob types? As String?

PHP 7.4 Typed property with floats / doubles

I apologise in advance if this is a lame question, Its my first.
I am building a small framework for a university project and I wanted to enforce types as much as possible, Great to see now that PHP 7.4 has strict types for properties,
But it is not being properly enforced even with declare strict_types.
Also on a side note, I know people say in PHP there is no difference between doubles and floats, but with typed properties, PHP does not recognise double as a data type.
See the simple code test below:
class FloatTest
{
private float $float;
private int $int;
function __construct()
{
}
public function setFloat(float $float):void
{
$this->float = $float;
}
public function getFloat()
{
return $this->float;
}
public function setInt(int $int):void
{
$this->int = $int;
}
public function getInt():int
{
return $this->int;
}
}
$ft = new FloatTest();
$ft->setFloat(8);//No error is thrown, converts to float but no decimals
$ft->getFloat();// Returns number 8 as float, but there is no enforcing of decimal point?
var_dump(is_float(8));//returns false
//Argument 1 passed to FloatTest::setInt() must be of the type int, float given
$ft->setInt(8.2);//Works as expected, great!
class DoubleTest
{
private double $double;
function __construct()
{
# code...
}
public function setDouble(double $double):void
{
$this->double = $double;
}
public function getDouble():double
{
return $this->double;
}
}
$dt = new DoubleTest();
//Argument 1 passed to DoubleTest::setDouble() must be an instance of double, int given:
$dt->setDouble(8);
$double = $dt->getDouble();
var_dump(is_double(8)); returns false
Based on this very simple test I have a few points which I find strange:
Why is PHP correctly enforcing the int type but not the float type?
Why is it that when I check with is_float() it returns false but the function accepts an integer?
Why is the integer type perfectly enforced but not the float?
Even though PHP has a valid double data type, why does it assume double is an instance?
double is definitely a primitive data type within PHP, as the is_double() function works perfectly,
See exception thrown above.
Basically what would be the best, cleanest work around to enforcing decimal numbers in PHP?
Why is PHP correctly enforcing the int type but not the float type?
Why is it that when I check with is_float() it returns false but the
function accepts an integer?
Because float range can contain integers without losing any data. In other words, float is like a superset of integers, so you can't say I only want floats i don't want integers even in strongly typed languages and even if your code is in strict_types mode.
Why is the integer type perfectly enforced but not the float?
PHP type declaration comes with coercive mode as default mode, so it's possible to change the declared type and no TypeError will be thrown only if it's possible for PHP to coerce values of the wrong type into the expected ones.
In your case you are passing 8(integer) to a method that expects a float, this is totally fine and PHP will not complain about it because coercing 8 to a float will not change anything/lose anything.
So what does strict_types do then ?
It will change the behavior of PHP from coercive to strict. That means PHP will not be tolerant when an involved operation could lead to data loss.
By taking your example when we set declare(strict_types=1) the following line will be a problem
$ft->setInt(8.2);//Works as expected, great!
Because we are trying to pass a float number to an int parameter which means a data loss (8.2 becomes 8 ) PHP will throw an exception
Fatal error: Uncaught TypeError: Argument 1 passed to
FloatTest::setInt() must be of the type int, float given
Even though PHP has a valid double data type, why does it assume
double is an instance? double is definitely a primitive data type
within PHP, as the is_double() function works perfectly
PHP has no double data type and is_double is just an alias of is_float()
Basically what would be the best, cleanest work around to enforcing
decimal numbers in PHP?
What you did is the best and cleanest work :)

Can you include meta-data into a generated flat buffer header?

I am currently sending data between my PC and an ARM M4 Microcontroller via UART. I've defined my own protocol where each message looks like this:
[START_CHAR LEN TYPE SEQ DATA CRC]
The START_CHAR and LEN fields help me determine when the data ends, after which I look up the TYPE (constant offset of 3) to figure out what data came in order to unpack it into a message class.
Now I'm looking into flatbuffers and it seems perfect except that I cannot encode the TYPE into the message without including it inside the actual message. Here is what I am trying to do:
namespace FlatMessage;
uint8 const TYPE = 50; // does not compile
table String {
value:string;
}
root_type String;
I could create an Enum but that is messy. Thank you!
[EDIT] I should add that I could just change the protocol to have an END_CHAR but I need to support the TYPE field for legacy reasons.
Well actually, I suppose I would still need the type to figure out how to deserialize it as a flatbuffer.
e.g.
uint8_t *buf = builder.GetBufferPointer(); // I can do this with END_CHAR because I could get the buffer.
auto receive_string = GetString(buf); // But I wouldn't know what the type is. e.g. this could be GetCoolString(buf).
You have a couple of options to store a type with a FlatBuffer:
Prefix a buffer yourself with a type.
Use the file_identifier feature of FlatBuffers, to make it possible to identify the type of FlatBuffer.
Store the type in FlatBuffers itself, by using a union type. Make the root table have a single union field.

Acitve Directory: Handling attributes with LARGE_INTEGER / INTEGER8 syntax

I have an vb.net app that handles directory service attributes. I have to display the attribute values. To get the values I use LDAP.
Microsoft's Active Directory has the syntax (or type) LARGE_INTEGER / INTEGER8. I saw various LDAP-Browsers that display this type of attribute as DateTime. But Microsoft's documentation says that this syntax (or type) is a 64-bit signed integer value.
My question: Does the schema definition provide an information where I can detect that an attribute with the LARGE_INTEGER syntax should be handled as DateTime or not?
Here is an example:
lastLogoff -> DateTime
msExchVersion -> No DateTime
Both attributes have the same syntax.
Thank you for helping!
Yes. The LARGE_INTEGER thing is an abstraction at the ADSI layer. If you look at the docs for the lastLogoff attribute, for example (http://msdn.microsoft.com/en-us/library/ms676822(v=vs.85).aspx), you'll see the actual AD syntax is Interval. You can grab the syntax for a given attribute off the attribute definition in the schema.
Regarding to the following post it seems that there is no way to see whether a LARGE_INTEGER attribute should be handled as DateTime or not :\
Same datatype Storage but different representation in AD (UsnChanged and LastLogon)

DB2 SQL array in attribute-defs of user defined type

I have a question concerning user defined types in DB2(v. 9.7.0.441). I want to create a type which has an attribute-array of another user defined type. Let me show you what I mean by a brief (fictional) example:
This is the UDT I want to use in another type
CREATE TYPE sport AS
(
Sport VARCHAR(10)
) MODE DB2SQL;
This is the UDT which should use the one above
CREATE TYPE person AS
(
plays sport ARRAY[3] // 'REF(sport)' or 'plays VARCHAR(10) ARRAY[3]' don't work either
) MODE DB2SQL;
DB2 just says that the token ARRAY[3] is unexpected.
Any hint what could be wrong here? By now it would be enough to have an CHAR Array in a UDT...
Thanks in advance
Ok ok,
according to db2's CREATE TYPE (array) statement "an array type can only be used as the data type of:
A local variable in a compound SQL (compiled) statement
A parameter of an SQL routine
A parameter of a Java procedure (ordinary arrays only)
The returns type of an SQL function
A global variable
and
A variable or parameter defined with an array type can only be used in compound SQL (compiled) statements
"
So its just not possible to use an array type inside a user defined type :-/
I would assume something like the following...
CREATE TYPE sport AS(Sport VARCHAR(10)) MODE DB2SQL;
CREATE TYPE PersonT AS(plays SportT ARRAY[3]) MODE DB2SQL;
CREATE TYPE SportArrayT AS SportT ARRAY[3];
CREATE TYPE PersonT AS (plays SportT SportArrayT) MODE DB2SQL;
However, the 3rd statement fails. Obviously an array of a user-defined type (or REF(SportT)) is not allowed :-(
Have a look at the doc for CREATE TYPE (array).
I'm not really sure what you're trying to do but the examples they give are like this:
CREATE TYPE CAPITALSARRAY AS VARCHAR(30) ARRAY[VARCHAR(20)]