I want to add columnDefs before initializing datatable, only if the column exists. How do i add the if else check?
I want do something like this
if(columnexists)
$('#dailyReportTable').dataTable().append(columnDefs)
else
$('#dailyReportTable').dataTable().append(Someother_columnDefs)
Related
I want to delete a column from a table in WordPress.
I tried many ways but either they don't work or they delete the whole row.
But I just want to remove the status column.
I have a lot of tables and I can't delete them manually.
Is there a solution in WordPress?
I used the following code but it doesn't work and it doesn't remove the column
function remove_status_database()
{
$table_name ="wp_order_status";
$column_name = "status";
$drop_ddl = true;
maybe_drop_column($table_name , $column_name ,$drop_ddl );
}
Example of the image .
Have you tried to do it with https://de.wordpress.org/plugins/wp-optimize/ ?
you can simple select the specific table and remove it.
hth
Stefano
I found the answer to my question. I can do a column with the following sql command.
$wpdb->query("ALTER TABLE wp_order_license DROP status" );
I have some data that looks as follows
As seen, the req_uri column, has data that contains ids after the second slash. I am only interested in the stem of the uri, that is the part before the second uri.
How can I create a view, where the req_uri is updated to only contain values in either '/v1/org' or '/v1/registration'
event_id req_uri
0007845f-cf6c-4513-9a5f-96d02482ef78 /v1/org/6970b2a5-e220-4d68-8fc0-2992a1b8bdb7
000a1fb0-ac4d-489e-866a-7c07caebb959 /v1/registration
000fe2a9-6d76-4045-93ac-9df68971539c /v1/org/6970b2a5-e220-4d68-8fc0-2992a1b8bdb7
0017e50b-c7b5-4e42-b670-f2d9f0af752f /v1/org/e536c1ed-4822-4b88-8c01-9f14c1c583e3/apps
0025a81f-cf81-4c60-8a39-3a626c1092a3 /v1/org/6970b2a5-e220-4d68-8fc0-2992a1b8bdb7
00304cef-87f3-426b-984c-b0b906b4815a /v1/org/e536c1ed-4822-4b88-8c01-9f14c1c583e3/apps
I know how to create views, as follows
CREATE VIEW V_MyView
AS SELECT event_id, req_uri
FROM tableName;
I also know how trim it as follows
update req_uri set req_uri = '/v1/org' where req_uri like '/v1/org%'
However, how can I combine this inside of a view, so that it contains the trimmed data?
Not sure I follow your question 100%, but I think you are asking how to make a view that has an altered hard-coded manipulation of req_uri, so something like this is what you want:
CREATE VIEW V_MyView
AS
SELECT event_id,
CASE WHEN req_uri LIKE '/v1/org%' THEN '/v1/org'
WHEN req_uri LIKE '/v1/registration%' THEN '/v1/registration'
ELSE NULL END as [req_uri]
FROM tableName;
Good day. I would like to know why a Parameter Request pops up when executing a query. I have a form with 2 comboboxes where the 2nd one depends on the value in the 1st one. I do know how to do this when it involves 2 tables. I am having trouble when there is a many to many relationship.
Table 1: name - Supply_Sources, fields - Source_ID(pk), SupplySourceName
Table 2: name - Warehouse_Locations, fields - WLocation_ID(pk), Location_Name
Table 3 (junction): name - SupplySource_WarehouseLocation, fields - Supply_Source_ID(pk), Location_In_ID(pk)
On my form frmInventoryReceivedInput I have cboSupplySource and cboWLocation.
I populate cboSupplySource with
SELECT [Supply_Sources].[Source_ID], [Supply_Sources].[SupplySourceName] FROM Supply_Sources;
I am trying to get a drop down list in the cboWLocation based on the value in cboSupplySource. I am wanting to see the location names of where the supplies are placed in the warehouse.
I have a requery in cboSupplySource After Update (with cboWLocation as the control name). The SQL that I have come up with so far is:
SELECT Warehouse_Locations.Location_Name,
SupplySource_WarehouseLocation.Supply_Source_ID,
SupplySource_WarehouseLocation.Location_In_ID
FROM Warehouse_Locations RIGHT JOIN (Supply_Sources LEFT JOIN
SupplySource_WarehouseLocation ON Supply_Sources.Source_ID =
SupplySource_WarehouseLocation.Supply_Source_ID) ON
Warehouse_Locations.WLocation_ID =
SupplySource_WarehouseLocation.Location_In_ID
WHERE (((Warehouse_Locations.Location_Name)=[frmInventoryReceivedInput].[cboSupplySource]));
When it runs, on tabbing out of cboSupplySource, Enter Parameter Value dialogue box pops up, looking for frmInventoryReceivedInput.cboSupplySource input. Nothing I input brings up the correct list in cboWLocation.
Obviously, I do not have the correct select statement. Any help would be appreciated.
For cboWLocation try the recordSource query:
SELECT Warehouse_Locations.Location_Name
FROM Warehouse_Locations INNER JOIN (Supply_Sources INNER JOIN
SupplySource_WarehouseLocation ON Supply_Sources.Source_ID =
SupplySource_WarehouseLocation.Supply_Source_ID) ON
Warehouse_Locations.WLocation_ID =
SupplySource_WarehouseLocation.Location_In_ID
WHERE ((Supply_Sources.SupplySourceName)=([Forms]![frmInventoryReceivedInput].[cboSupplySource]))
Be aware, that the combobox columns have to be set to columncount 1 in this case with appropriate column width, because you said you only want to see the location names. Further, you should be sure that cboWLocation is not bound to a Control Source, to not overwrite anything.
You can apply it in VBA at the cboWLocation Enter Event.
In the following code example, the combobox cboWLocation is only updated, if there is a value in combobox cboSupplySource.
Private Sub cboWLocation_Enter()
If not (isNull(Me!cboSupplySource) Or Me!cboSupplySource.ListIndex = -1) then
Me.cboWLocation.RowSource = strSQL 'Put here the previous mentioned SQLString
End if
End Sub
HINT: It would be better for performance, when you change the bound column in cboSupplySource to the PK SourceID instead of the name. (With two columns in combobox cboSupplySource) Then use this PK to compare in your WHERE statement instead of the name. this is what keys in tables are for.
Edit: In the WHERE statement, maybe you have to put the namecomparison between ' ' because it is a string
I would like to be able to get the ID of my record in my sql statement:
$result = $db->query("select id,FQDN, ip_address, .....");
However, I don't want it to show up in the export using headings:
$headings = array('Name (FQDN)','Management IP Address', ......");
Is it possible to hide the ID value?
Thanks
Columns or rows can be set to "HIDDEN"
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible(false);
will hide column C
or
$objPHPExcel->getActiveSheet()->getRowDimension(5)->setVisible(false);
will hide row 5
I am trying to save a new object to the database using petapoco.
I have an object that uses a Guid for the primary key.
Here is an example of the objects primary key property.
<PetaPoco.Column()> _
Public ReadOnly Property Primkey() As Guid Implements IStandardDocument.Primkey
Get
Return (_primkey)
End Get
End Property
Here is an example of the save method.
database.Save("Reservations", "Primkey", reservation)
The sql that is generated is an update with a primkey of 00000000-0000-0000-0000-000000000000 instead of an insert. So new records are never inserted.
If I have an existing object with a valid guid the update and delete all work correctly.
What am I doing wrong for the save case?
Most likely it's too late to answer this for the original poster, but for others out there...
My understanding is the Save doesn't work for Guid columns. The way petaPoco knows if it's an insert vs update is if the key value is different from default. In case if numeric it would be 0, in the case of Guid it would be '00000000-0000-0000-0000-000000000000'.
Here's an extract of IsNew method
// Common primary key types
if (type == typeof(long))
return (long)pk == 0;
else if (type == typeof(ulong))
return (ulong)pk == 0;
else if (type == typeof(int))
return (int)pk == 0;
else if (type == typeof(uint))
return (uint)pk == 0;
// Create a default instance and compare
return pk == Activator.CreateInstance(pk.GetType());
In the case of Guid the last statement would always return false, even if your primary key is all zeros. There should really be another else if as such:
else if (type == typeof(Guid))
return Guid.Equals(pk, Activator.CreateInstance(pk.GetType()));
However, I didn't check if this is the only thing that has to be changed for the GUID key to work. After inserting the record, PetaPoco tries to check the key value of the newly inserted record and it might fail on that too.
I was able to make this work by removing the type from the primkey property.
Setting the primkey to null will now return null rather than an empty guid.
PetaPoco now sees the primarykey field is a null and generate the correct insert statement rather than generating an update statement for primkey 00000000-0000-0000-0000-000000000000.
I've never worked with petapoco but a few things I would try first are:-
Primkey column's Data Type in sql is 'Uniqueidentifier'
Primkey column's Default Value is (newid())
Change the PrimKey to a Get/Set value and do 'Primkey = Guid.NewGuid' before saving.
EDIT: I just thought, when you declare a New Reservation does it allow you to pass an ID ect on the constructor?