tcms api filters with date range - kiwi-tcms

I'm trying to use tcms-api module with filter function.
https://tcms-api.readthedocs.io/en/latest/modules/tcms_api.html#module-tcms_api
I want to filter the result by date range, so collect the test cases between the date range, trying below code, but it's not working,
start_date = datetime.datetime(2021, 2, 8)
end_date = datetime.datetime(2021, 2, 9)
rpc_client = TCMS()
for test_case in rpc_client.exec.TestCase.filter({'create_date__range': '(start_date, end_date)'}):
print(test_case)
I have tried different formats, also trying to refer to the following too, that not helps.
https://docs.djangoproject.com/en/dev/ref/models/querysets/#range
Getting Following error,
File "/usr/lib64/python3.6/xmlrpc/client.py", line 656, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault -32603: "Internal error: ['“(” value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format.']">
How can this be used to filter the results based on date ranges?

rpc_client.exec.TestCase.filter({'create_date__range': '(start_date, end_date)'}):
The value you pass should be a tuple, not a string so remove the quotes.
Then there's a possibility that the XMLRPC serialization layer doesn't know how to encode this value but you will have to check it out. There could be a bug hiding somewhere in there.

Related

SSRS String to Date conversion (mmddyyyy)

I have a String field in a Dataset in (mmddyyyy) format.
I am trying to convert it into a Date field in SSRS.
I already tried using the below command but I am getting error.
CDate(Fields!LocalTXNDate.Value)
Can anyone please suggest.
While Larnu is correct, the way to do it is to correct the database, sometimes we lowly report makers have no say in making these changes - much less getting a DBA to do it in a reasonable amount of time.
If you can't change the data to be correct, the easiest way to convert and use the field as a date is to add a Calculated Field to the Dataset. Open the dataset properties, click on the Fields tab, Add a Calculated field.
For the Expression, use string functions to parse the field into a generic date format and then CDATE to convert to a date type. Then use the new field for dates. You could also use this in your text box if it's not being reused but it's easier to manipulate the Calculated field.
=CDATE(
RIGHT(Fields!LocalTXNDate.Value, 4) & "-" &
LEFT(Fields!LocalTXNDate.Value, 2) & "-" &
MID(Fields!LocalTXNDate.Value, 3, 2)
)
The problem here isn't SSRS but your data, and that you are using a string based data type to store the data. You need to fix the problem at the source, not at the report level.
The string format you have chosen, MMddyyyy isn't a format that is recognised by default in any of the languages in SQL Server, nor if you explicitly use SET DATEFORMAT, nor does it appear as a style. SET DATEFORMAT MDY; SELECT CONVERT(date,'11172022'); will fail. Therefore you'll need to first do some string manipulation on the data first to be an unambiguous format (yyyyMMdd):
UPDATE YT
SET YourDateColumn = CONVERT(varchar(8),V.DateValue,112)
FROM dbo.YourTable YT
CROSS APPLY (VALUES(TRY_CONVERT(date,CONCAT(RIGHT(YT.YourDateColumn,4),LEFT(YT.YourDateColumn,4)))))V(DateValue);
For any bad values you have, such as '17112022' this will UPDATE the value to NULL; as such you may want to create a new column for the new value, or perhaps a new column to store the value of dates that couldn't be converted.
After you've changed the value to an unambiguous format, then you can ALTER the column:
ALTER TABLe dbo.YourTable ALTER COLUMN YourDateColumn date NULL;
Note that if you have any constraints, you will need to DROP those first, and then reCREATE them afterwards.
Now that the data type of the column is correct, you need not do anything in SSRS, as the data type is correct.

Dynamic Date using Analysis Services in Report builder

Looking for help on this one. I'm working on a report in Report Builder that uses data from the Analysis Services cube and it is giving me a lot of problems when it come to any date/time data. I am trying to build a dynamic report that will allow the report to update depending on when it is viewed. I do this by setting parameters (#FromDateDate and #ToDateDate). Unfortunately MDX seems to hate dates which makes no sense to me.
My goal is to get data over a span of three months with the #ToDateDate being Today() and the #FromDateDate being 3 months in the past which I am able to achieve with this function (=DateAdd(DateInterval.Day,-90,Today()) ). However those don't go well with MDX.
My query looks like this:
SELECT
NON EMPTY
{[Measures].[Work Item Count]} ON COLUMNS
,NON EMPTY
{
[Date].[Year - Month - Date Hierarchy].[Date].ALLMEMBERS*
[Work Item].[System_State].[System_State].ALLMEMBERS*
[Work Item].[Microsoft_VSTS_Common_Severity].[Microsoft_VSTS_Common_Severity].ALLMEMBERS
}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM
(
SELECT
StrToMember
(#FromDateDate
,CONSTRAINED
)
:
StrToMember
(#ToDateDate
,CONSTRAINED
) ON COLUMNS
FROM
(
SELECT
{[Work Item].[System_WorkItemType].&[Bug]} ON COLUMNS
FROM
(
SELECT
{
[Team Project].[Team Project Hierarchy].&[{6F43CBFD-2E98-4CA7-B428-0B732603517A}]
} ON COLUMNS
FROM [Work Item]
)
)
)
WHERE
(
[Team Project].[Team Project Hierarchy].&[{6F43CBFD-2E98-4CA7-B428-0B732603517A}]
,[Work Item].[System_WorkItemType].&[Bug]
)
CELL PROPERTIES
VALUE
,BACK_COLOR
,FORE_COLOR
,FORMATTED_VALUE
,FORMAT_STRING
,FONT_NAME
,FONT_SIZE
,FONT_FLAGS;
I was able to figure out how to essentially inject he appropriate format by adjusting my Parameter Values in the Dataset Properties to this -
="[Date].[Date].&["+format(Parameters!FromDateDate.Value,"yyyy-MM-ddThh:mm:ss")+"]"
My two parameters have default values of :
=DateAdd(DateInterval.Day,-90,Today()) and =Today()
When I run my report I get the following error:
The restrictions imposed by the CONSTRAINED flag in the STRTOMEMBER function were violated.
Now if I remove CONSTRAINED from the STRTOMEMBER function I get another error. I have also tried removing the entire STRTOMEMBER function and just using the parameters which I can get to work in Management Studio but not in Report builder. Please Help! I have attempted so many different ways and still no success. Let me know what additional information is needed.
Another thing -
If I remove the T in the date format of the Parameter Value in the Dataset Property to look like this:
="[Date].[Year - Month - Date Hierarchy].[Date].&["+format(Parameters!FromDateYearMonthDateHierarchy.Value,"yyyy-MM-dd hh:mm:ss")+"]"
I get the below error:
The '2017-06-08 12:00:00' string cannot be converted to the date type.
So here is the solution if anyone is interested. I've seen a ton of forum posts online with no one having a concrete answer so I can see this is a common problem - the workaround at this link is valid and does work:
Using Dynamic MDX in Reporting Services
My issue was the format of my "injected" date. When running the query generated by my #ToDateDate and #FromDateDate parameters...
(note: after changes I made my parameters are now
#FromDateYearMonthDateHierarchy and '#ToDateYearMonthDateHierarcy`
which you will notice in my Parameter Value function)
My Parameter Values appeared in the following format:
[Date].[Year - Month - Date Hierarchy].[Date].&[2010-12-31T00:00:00]
In order to fix the issue for me my "injection statement" had to look like this:
"[Date].[Year - Month - Date Hierarchy].[Date].&[" & Format(CDate(Parameters!FromDateYearMonthDateHierarchy.Value),"yyyy-MM-dd") & "T00:00:00]"
With the actual date formatting of "yyyy-MM-dd") & "T00:00:00]" so in the end the hours minutes and second was what was giving me the headache. The injection works perfectly but just need to pay attention to the Formatting of the date and time. I genuinely hope this helps someone!

VB.Net - Excel application get showing values of an range

I'm trying get an Excel Range and copy into an array of objects with Vb.Net.
This is not a problem. I use the following code:
Dim vValues(,) As Object = ExcelApp.Range(vRange).Value
And works fine; but I have a the following case:
In the column "C"; the value has a specific format and internally has another value.
My question is:
Somebody know the way to get the information exact as the user see?
I'm trying to get the information without use a For ... Each or some kind of cycle.
I'm also tried to avoid use "text to columns" function.
Both seems right solutions, but would impact the performance with a lot of data.
FYI: Also I can get the information through the ODBC connection; but I'm searching the solution using a Range
Exactly what the user sees is the Text property. But you cannot have an array of that, you will have to query each cell individually.
You are getting a Double value in your array instead of a DateTime value because you have "Time" formatting applied in Excel. If you had a format from the "Date" category, Excel would instead send a proper Variant/Date, not a Double that represents it.
Another option would be constructing the DateTime objects on the .NET side, provided you know in which columns they should be.

LINQ converting date, need to handle bad date

I'm using LINQ-to-SQL and need to order by a date field. The date field is stored as text and could have anything in it since it is user entered data. I need to handle cases where an invalid date was placed in there.
For example, a date of "02/23/0000" returns:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
I need to avoid errors and I don't care where an invalid date like this gets sorted to. The parameters of the project mean I can't modify my source data, only read from it.
Here is an example LINQ statement.
from x in dbo_myTable
orderby Convert.ToDateTime(x.MyDateField)
select x
Do you definitely need to perform the ordering in the database? In this situation I would strongly consider pulling all of the data, then performing some conversion in .NET code where you have a great deal more control over what's going on, and then order it still in .NET code.
Ultimately, dealing with screwed up data in this sort of situation is tricky - the more control you have, the better.
You can do something like this (Based on your comment that they are all 10 characters)
from x in dbo_myTable
orderby x.MyDateField.Substring(6, 4), x.MyDateField.Substring(0, 2), x.MyDateField.Substring(3, 2)
select x
First is first; why cant you change the database to fix you obviously brokes table structure? Why cant you sanitize input when its going into the database? Why are you not validating user input?
Now for the answer; your only option is attempt to parse the date (with DateTime.TryParse or DateTime.TryParseExact) and set a default value of your choosing if it fails to parse:
from x in dbo_myTable
orderby TryConvertToDateTime(x.MyDateField)
select x
private DateTime TryConvertToDateTime(string dt)
{
DateTime rtn = DateTime.MinValue; // or whatever you want your default to be
DateTime.TryParse(dt,out rtn);
return rtn;
}

Dateformat mismatch in sql server and C# code

I have a problem.
I have an application in C# with SQL SERVER 2005 as backend.
The problem is in fetching the correct record based on the date.
The frontend code is
if (string.IsNullOrEmpty(txtFromDate.Text))
SelectCmd.Parameters[0].Value = DBNull.Value;
else
SelectCmd.Parameters[0].Value = txtFromDate.Text;
Now if I run usp_NewGetUserDetail '03/04/2010' in the query analyser, I am able to get the correct record.
So I am preety confident that my SP is correct(I have tested with many variations).
But if the same value is passed from front end code(SelectCmd.Parameters[0].Value = "03/04/2010";), I am getting some unexpected record. By that I mean , the records which are not in the date range.
I guess that there is some mismatch in date format of backend and frontend.
Kindly let me know if I missed out some information that I need to provide for solving this
Please help.
Dealing with dates on SQL Server is a tricky business, since most formats are language- and locale-dependent. As Adam already mention - you should try to avoid dealing with dates as strings - it does get messy, and using DateTime (both in .NET and in T-SQL) is much safer and easier.
But if you must use strings, then be aware of these points: a date like 02/05/2010 will be interpreted as Feb 5, 2010 in some places, or as May 2, 2010 in others. So whatever you're doing - you'll always run into someone who has a different setting and gets different results.
The way to do here is to use the ISO-8601 format which is independent of all locale and language settings and just always works.
So for your dates, always use the YYYYMMDD format - first of all, it always works, and second of all, with that format, you get a "natural" sort behavior - sorted by Year, then Month, then Day.
There's no need to pass the date as a string, nor should you. Set the value of the parameters to a DateTime object that represents the date you want, not the string representation of it.
Try something like this:
DateTime fromDate;
if (DateTime.TryParse(txtFromDate.Text, out fromDate))
{
SelectCmd.Parameters[0].Value = fromDate
}
else
{
SelectCmd.Parameters[0].Value = DBNull.Value;
}

Resources