qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
229,630
|
<p>My application has several threads:
1) Main Thread
2) 2 Sub-Main Threads (each with Message Loop, as shown below), used by TFQM
3) n Worker Threads (simple loop, containing Sleep())</p>
<p>My problem is, when I close my application, the Worker Threads manage to exit properly, but 1 of the 2 Sub-Main Threads hangs (never exits) when I issue WM_QUIT to close them.</p>
<hr>
<pre><code>procedure ThreadProcFQM(P: Integer); stdcall;
var
Msg: TMsg;
_FQM: TFQM;
begin
_FQM := Ptr(P);
try
_FQM.fHandle := AllocateHwnd(_FQM.WndProc);
while GetMessage(Msg, 0, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
finally
DeallocateHWnd(_FQM.fHandle);
SetEvent(_FQM.hTerminated);
end;
end;
</code></pre>
<hr>
<pre><code>procedure TFQM.Stop;
begin
PostMessage(fHandle, WM_QUIT, 0, 0);
WaitForSingleObject(hTerminated, INFINITE);
if hThread <> INVALID_HANDLE_VALUE then
begin
CloseHandle(hThread);
hThread := INVALID_HANDLE_VALUE;
end;
end;
</code></pre>
|
[
{
"answer_id": 229808,
"author": "Davy Landman",
"author_id": 11098,
"author_profile": "https://Stackoverflow.com/users/11098",
"pm_score": 3,
"selected": false,
"text": "PeekMessage(CurrentMessage, 0, WM_USER, WM_USER, PM_NOREMOVE);\n"
},
{
"answer_id": 230288,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "while not PostThreadMessage(ThreadID, idStartMessage, 0, 0) do\n Sleep(1);\n idExitMessage = WM_USER + 777; // you are free to use your own constant here\n PostThreadMessage(ThreadID, idExitMessage, 0, 0);\n WaitForSingleObject(ThreadHandle, INFINITE);\n procedure ThreadProcFQM; stdcall;\nvar\n Msg: TMsg;\nbegin\n while GetMessage(Msg, 0, 0, 0) \n and (Msg.Message <> idExitMessage) do\n begin\n TranslateMessage(Msg);\n DispatchMessage(Msg);\n end;\nend;\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30787/"
] |
229,632
|
<p>In a C program (p1), how to launch a dynamically constructed command (and its arguments) that reads its standard input from p1's standard output?</p>
<p>Note that: </p>
<ol>
<li><p>A method other than this stdout -->
stdin piping is also OK <strong>provided</strong>
it is <strong>PORTABLE</strong> across Windows and
Linux.</p></li>
<li><p>I cannot use C++, Java, Perl, Ruby,
Python, etc here.</p></li>
</ol>
<p>Also, will this have a MinGW dependency for its Windows build?</p>
<p><strong>REOPENED</strong>: The question below answers it for Linux, but this question wants a portable method.
<a href="https://stackoverflow.com/questions/70842/execute-program-from-within-a-c-program">Execute program from within a C program</a></p>
|
[
{
"answer_id": 229786,
"author": "Pieter",
"author_id": 5822,
"author_profile": "https://Stackoverflow.com/users/5822",
"pm_score": 2,
"selected": false,
"text": " bp::child cs = p.start();\n bp::postream& os = cs.get_stdin();\n"
},
{
"answer_id": 230091,
"author": "bk1e",
"author_id": 8090,
"author_profile": "https://Stackoverflow.com/users/8090",
"pm_score": 2,
"selected": false,
"text": "_popen popen"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229632",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10955/"
] |
229,633
|
<p>I want my <kbd>AltGr</kbd> key to behave exactly like left <kbd>Alt</kbd>.<br>
Usually, I do this kind of stuff with <a href="http://www.autohotkey.com/" rel="noreferrer">Autohotkey</a>, but I'm open to different solutions. </p>
<p>I tried this:</p>
<pre><code>LControl & RAlt::Alt
</code></pre>
<p>And Autohotkey displayed error about <code>Alt</code> not being recognized action.<br>
Then I tried the following code:</p>
<pre><code>LControl & RAlt::
Send {Alt down}
KeyWait LCtrl
KeyWait Ralt
Send {Alt up}
return
</code></pre>
<p>which sort of works - I'm able to use the <kbd>AltGr</kbd> key for accessing hotkeys, but it still behaves differently:<br>
When I press and release the left <kbd>Alt</kbd>, the first menu item in the current program receives focus.<br>
Pressing and releasing <kbd>AltGr</kbd> with this script does nothing. </p>
<p>Any ideas? Is this even possible with Autohotkey? (remapping right <kbd>Ctrl</kbd> and <kbd>Shift</kbd> to their left siblings was piece of cake)</p>
<p><hr>
Note: I tried switching <code>Alt</code> to <code>LAlt</code> in the code and it made no difference.</p>
|
[
{
"answer_id": 229716,
"author": "Brian Schmitt",
"author_id": 30492,
"author_profile": "https://Stackoverflow.com/users/30492",
"pm_score": 0,
"selected": false,
"text": "LControl & RAlt::!\n <^>!::!\n"
},
{
"answer_id": 230369,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 2,
"selected": false,
"text": "LControl & RAlt::Send {Alt}\nRAlt::Alt\n"
},
{
"answer_id": 396859,
"author": "Ronald Blaschke",
"author_id": 49604,
"author_profile": "https://Stackoverflow.com/users/49604",
"pm_score": 3,
"selected": false,
"text": "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout Windows Key Caps Lock Windows Key Caps Lock"
},
{
"answer_id": 460800,
"author": "Tomas Sedovic",
"author_id": 2239,
"author_profile": "https://Stackoverflow.com/users/2239",
"pm_score": 7,
"selected": true,
"text": "Windows Registry Editor Version 5.00\n\n[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout]\n\"Scancode Map\"=hex:00,00,00,00,00,00,00,00,02,00,00,00,38,00,38,e0,00,00,00,00\n"
},
{
"answer_id": 3079446,
"author": "Dave James Miller",
"author_id": 167815,
"author_profile": "https://Stackoverflow.com/users/167815",
"pm_score": 2,
"selected": false,
"text": "LControl & *RAlt::Send {LAlt Down}\nLControl & *RAlt Up::Send {LAlt Up}\n LControl & *RAlt::Send {LWin Down}\nLControl & *RAlt Up::Send {LWin Up}\n"
},
{
"answer_id": 26817583,
"author": "Ashish Porwal",
"author_id": 4230206,
"author_profile": "https://Stackoverflow.com/users/4230206",
"pm_score": 1,
"selected": false,
"text": "[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout]\n\"Scancode Map\"=hex:00,00,00,00,00,00,00,00,02,00,00,00,38,00,38,e0,00,00,00,00\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2239/"
] |
229,643
|
<p>Following on from a <a href="https://stackoverflow.com/questions/221417/how-do-i-programmatically-access-the-target-path-of-a-windows-symbolic-link">previous question</a>, I am creating a symbolic link on a Server 2008 from a Vista machine using UNC paths. I can create the link just fine. I can go to the Server 2008 box and double click on the link in explorer to open the target file. What I cannot do though is use FileCreateW to get a handle to the UNC path link (from the Vista box). When I try it, it fails and GetLastError() returns error code 1463 (0x5B7), which is:</p>
<blockquote>
<p>The symbolic link cannot be followed because its type is disabled.</p>
</blockquote>
<p>How to enable its "type" in Server 2008 (assuming the error means what it says)?</p>
|
[
{
"answer_id": 230047,
"author": "David Arno",
"author_id": 7122,
"author_profile": "https://Stackoverflow.com/users/7122",
"pm_score": 6,
"selected": false,
"text": "fsutil behavior set SymlinkEvaluation L2L:1 R2R:1 L2R:1 R2L:1\n"
},
{
"answer_id": 2556247,
"author": "mklement0",
"author_id": 45375,
"author_profile": "https://Stackoverflow.com/users/45375",
"pm_score": 7,
"selected": true,
"text": "fsutil.exe fsutil behavior set /?\n fsutil behavior query SymlinkEvaluation fsutil behavior set SymlinkEvaluation L2L L2R R2L R2R L R L R 2 L R 2 fsutil behavior set SymlinkEvaluation R2L R L"
},
{
"answer_id": 23746597,
"author": "mwolfe02",
"author_id": 154439,
"author_profile": "https://Stackoverflow.com/users/154439",
"pm_score": 2,
"selected": false,
"text": "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem Name Type Data (1: Enabled; 0: Disabled)\n-------------------------------------------------\nSymlinkLocalToLocalEvaluation REG_DWORD 1\nSymlinkLocalToRemoteEvaluation REG_DWORD 1\nSymlinkRemoteToLocalEvaluation REG_DWORD 1\nSymlinkRemoteToRemoteEvaluation REG_DWORD 1\n"
},
{
"answer_id": 24364595,
"author": "Jake1164",
"author_id": 373334,
"author_profile": "https://Stackoverflow.com/users/373334",
"pm_score": 4,
"selected": false,
"text": "fsutil behavior query SymlinkEvaluation\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229643",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7122/"
] |
229,656
|
<p>I've got an error in my build which says:</p>
<blockquote>
<p>Error 12 Cannot implicitly convert
type
'System.Collections.Generic.IEnumerator< BaseClass>'
to
'System.Collections.Generic.IEnumerator< IParentClass>'.
An explicit conversion exists (are you
missing a cast?)</p>
</blockquote>
<p>Is it wrong to simply cast it away?</p>
<p>This is my code:</p>
<pre><code>public Dictionary<Int32, BaseClass> Map { get; private set; }
public IEnumerator<BaseClass> GetEnumerator()
{
return this.Map.Values.GetEnumerator();
}
public IEnumerator<IParentClass> IEnumerable<IParentClass>.GetEnumerator()
{
return this.GetEnumerator(); // ERROR!
}
</code></pre>
<p>My question is, can I just change this line:</p>
<pre><code>return this.GetEnumerator();
</code></pre>
<p>to:</p>
<pre><code>return (IEnumerator<IParentClass>)this.GetEnumerator();
</code></pre>
<p>(without any bad side effects)?</p>
<p><strong>Accepted Answer:</strong><br>
I've changed the function to the following (after reading Jon Skeet's post):</p>
<pre><code>IEnumerator<IParentClass> IEnumerable<IParentClass>.GetEnumerator()
{
return this.Map.Values.Cast<IParentClass>().GetEnumerator();
}
</code></pre>
|
[
{
"answer_id": 229667,
"author": "spoulson",
"author_id": 3347,
"author_profile": "https://Stackoverflow.com/users/3347",
"pm_score": 0,
"selected": false,
"text": "IEnumerator<BaseClass> IEnumerator<ParentClass> Select return this.Select(x => (IParentClass)x).GetEnumerator();\n Cast return this.Cast<IParentClass>().GetEnumerator();\n"
},
{
"answer_id": 229670,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "IEnumerable<BaseClass> IEnumerator<BaseClass> Enumerable.Cast public static IEnumerator<TParent> Upcast<TParent, TChild>\n (this IEnumerator<TChild> source)\n where TChild : TParent\n{\n while (source.MoveNext())\n {\n yield return source.Current;\n }\n}\n return this.Map.Values.Cast<BaseClass>().GetEnumerator();\n"
},
{
"answer_id": 229682,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "static class Program\n{\n static IEnumerator<Foo> GetBase() {\n yield return new Foo();\n yield return new Bar();\n }\n static IEnumerator<Bar> GetDerived()\n {\n return (IEnumerator<Bar>)GetBase();\n }\n static void Main()\n {\n var obj = GetDerived(); // EXCEPTION\n }\n}\n static IEnumerator<Bar> GetDerived()\n{\n using (IEnumerator<Foo> e = GetBase())\n {\n while (e.MoveNext())\n {\n // or use \"as\" and only return valid data\n yield return (Bar)e.Current;\n }\n }\n}\n"
},
{
"answer_id": 229695,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 0,
"selected": false,
"text": "Enumerator List void doStuff() {\n List<IParentThing> list = getList();\n list.add(new ChildThing2());\n}\n\nList<IParentThing> getList() {\n return new List<ChildThing1>(); //ERROR!\n}\n IParentThing ChildThing2 ChildThing1 ChildThing2 IParentThing ChildThing1 List<ChildThing1> List<IParent> IParentThing IParentThing ChildThing1"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/986/"
] |
229,664
|
<p>I have a native VC++ project that uses a dll (which is not in a project). Now, I must to put the dll in one the "Search Path Used by Windows to Locate a DLL"
<a href="http://msdn.microsoft.com/en-us/library/7d83bc18(VS.80).aspx" rel="nofollow noreferrer">link</a></p>
<p>but I don't want the dll to sit in the exectuable or current or windows or system directory.</p>
<p>So my only option according to that is adding the path to the %PATH% environment variable.</p>
<p>Is there any other way?</p>
<p>Is there an elegant way to do so (adding to PATH)? should I do this on installation? should I be concerned if i'm doing this?</p>
|
[
{
"answer_id": 231169,
"author": "spoulson",
"author_id": 3347,
"author_profile": "https://Stackoverflow.com/users/3347",
"pm_score": 0,
"selected": false,
"text": "LoadLibrary"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30324/"
] |
229,671
|
<p>I read the following in a review of Knuth's "The Art of Computer Programming":</p>
<p>"The very 'practicality' means that the would-be CS major has to learn Kernighan's mistakes in designing C, notably the infamous fact that a for loop evaluates the for condition repeatedly, which duplicates while and fails to match the behavior of most other languages which implement a for loop."</p>
<p>(<a href="http://www.amazon.com/review/R9OVJAJQCP78N/ref=cm_cr_pr_viewpnt#R9OVJAJQCP78N" rel="nofollow noreferrer">http://www.amazon.com/review/R9OVJAJQCP78N/ref=cm_cr_pr_viewpnt#R9OVJAJQCP78N</a>)</p>
<p>What is this guy talking about? How could you implement a for loop that wasn't just syntactic sugar for a while loop?</p>
|
[
{
"answer_id": 229694,
"author": "mweerden",
"author_id": 4285,
"author_profile": "https://Stackoverflow.com/users/4285",
"pm_score": 2,
"selected": false,
"text": "for i:=0 to N"
},
{
"answer_id": 229704,
"author": "Magnus Hoff",
"author_id": 2971,
"author_profile": "https://Stackoverflow.com/users/2971",
"pm_score": 6,
"selected": true,
"text": "for i:=0 to 100 do { ... }\n for i:=0 to final_value() do { ... }\n final_value for (int i=0; i<final_value(); ++i) // ...\n final_value int end = final_value();\nfor (int i=0; i<end; ++i) // ...\n"
},
{
"answer_id": 229723,
"author": "Tarski",
"author_id": 27653,
"author_profile": "https://Stackoverflow.com/users/27653",
"pm_score": 2,
"selected": false,
"text": "int x;\nfor (x = 10; x != 0; --x)\n{\n printf (\"Hello\\n\");\n}\n x = 0; x <= 10; ++x mov 10, eax\nloop:\nprint \"hello\"\ndec eax\njne loop\n jne print \"hello\"\nprint \"hello\"\nprint \"hello\"\nprint \"hello\"\nprint \"hello\"\nprint \"hello\"\nprint \"hello\"\nprint \"hello\"\nprint \"hello\"\nprint \"hello\"\n"
},
{
"answer_id": 229736,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 2,
"selected": false,
"text": "for while for (int i = 0; i < max; i++) { DoStuff(); }\n int i = 0; while (i < max) { DoStuff(); i++; }\n i < strlen(longConstantString) strlen for break while () {} do {} while ()"
},
{
"answer_id": 229743,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 2,
"selected": false,
"text": "mov ecx, 0x00000010h\nloop_start:\n;loop body\nloop loop_start\n;end of loop\n"
},
{
"answer_id": 229915,
"author": "codebunny",
"author_id": 13667,
"author_profile": "https://Stackoverflow.com/users/13667",
"pm_score": 3,
"selected": false,
"text": "for (i=0; i<100; i++) dostuff();\n for (i=0; i<strlen(s); i++) dostuff();\n slen = strlen(s);\nfor (i=0; i<slen; i++) dostuff();\n for (isread(fd, &buffer, ISFIRST);\n isstat(fd) >= 0;\n isread(fd, &buffer, ISNEXT)\n{\n dostuff(buffer);\n}\n isread(fd, &buffer, ISFIRST);\nwhile (isstat(fd) >= 0)\n{\n dostuff(buffer);\n isread(fd, &buffer, ISNEXT);\n}\n"
},
{
"answer_id": 229922,
"author": "T.E.D.",
"author_id": 29639,
"author_profile": "https://Stackoverflow.com/users/29639",
"pm_score": 2,
"selected": false,
"text": "q := 10;\nfor i in 1..q loop\n q := 20;\n --// Do some stuff\nend loop;\n q = 10;\nfor (int i=0;i<q;i++) {\n q = 20;\n // Do some stuff\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229671",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30529/"
] |
229,676
|
<p>Greetings,</p>
<p>The VBA code below will create an Excel QueryTable object and display it starting on Range("D2"). The specific address of this target range is immaterial.</p>
<p>My question is -- is it possible to manually feed in values to an in-memory Recordset, and then have the table read from it? In other words, I want to specify the table columns and values in VBA, not have them come from a database or file.</p>
<pre><code>Public Sub Foo()
Dim blah As QueryTable
Dim rngTarget As Range
Dim strQuery As String
strQuery = "SELECT * FROM MY_TABLE"
Set rngTarget = Range("D2")
Dim qt As QueryTable
Set qt = rngTarget.Worksheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=MY_SQL_SERVER;APP=MY_APP;Trusted_Connection=Yes", Destination:=rngTarget)
With qt
.CommandText = strQuery
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.Name = "MY_RANGE_NAME"
.MaintainConnection = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = False
.Refresh BackgroundQuery:=False
End With
End Sub
</code></pre>
|
[
{
"answer_id": 248530,
"author": "GSerg",
"author_id": 11683,
"author_profile": "https://Stackoverflow.com/users/11683",
"pm_score": 3,
"selected": true,
"text": " Dim vConnection As Variant, vCommandText As Variant\n Dim r As ADODB.Recordset\n Dim i As Long\n\n 'Save query table definition\n vConnection = QueryTable.Connection\n vCommandText = QueryTable.CommandText\n\n\n Set r = New ADODB.Recordset\n <populate r>\n\n Set QueryTable.Recordset = r\n QueryTable.Refresh False\n\n 'Restore Query Table definition\n Set QueryTable.Recordset = Nothing\n QueryTable.Connection = vConnection\n QueryTable.CommandText = vCommandText\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7311/"
] |
229,683
|
<p>I have a rails application that I am running with Vista,IIS7 and SQL 2005. For some reason the CSS is not being rendered. The CSS works fine when I use Webrick.</p>
<p>Any ideas how to get CSS working correctly with IIS7. I have uninstalled and reinstalled windows components "Common Http Features" with no luck.</p>
|
[
{
"answer_id": 229710,
"author": "Dylan Beattie",
"author_id": 5017,
"author_profile": "https://Stackoverflow.com/users/5017",
"pm_score": 2,
"selected": false,
"text": "Content-Type: text/css \n"
},
{
"answer_id": 4546765,
"author": "Adam Hockemeyer",
"author_id": 556074,
"author_profile": "https://Stackoverflow.com/users/556074",
"pm_score": 0,
"selected": false,
"text": "images/css/js"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/453046/"
] |
229,726
|
<p>I've seen <a href="https://stackoverflow.com/questions/49156/importing-javascript-in-jsp-tags">this question</a> regading the importing of js-files related to the tag content itself. I have a similar problem, here I have a jsp tag that generates some HTML and has a generic js-implementation that handles the behavior of this HTML. Furthermore I need to write some initialization statements, so I can use it afterwards through JavaScript. To be possible to use this "handler" within my JavaScript, it should be somehow accessible.</p>
<p>The question is... Is it Ok to write inline <script> tags along with my HTML for instantiation and initialization purposes (personally I don't think its very elegant)? And about being accessible to the JS world, should I leave a global var referencing my handler object (not very elegant aswell I think), are there better ways to do it? </p>
|
[
{
"answer_id": 229772,
"author": "pkaeding",
"author_id": 4257,
"author_profile": "https://Stackoverflow.com/users/4257",
"pm_score": 1,
"selected": false,
"text": "<script> <script>"
},
{
"answer_id": 229775,
"author": "Dennis",
"author_id": 17874,
"author_profile": "https://Stackoverflow.com/users/17874",
"pm_score": 0,
"selected": false,
"text": "<script> <script>"
},
{
"answer_id": 229776,
"author": "Magnar",
"author_id": 1123,
"author_profile": "https://Stackoverflow.com/users/1123",
"pm_score": 4,
"selected": true,
"text": " <script src=\"/javascript/article_admin.js\"></script> \n <script type=\"text/javascript\"> \n NP_ArticleAdmin.initialize({ \n text: { \n please_confirm_deletion_of: '<i18n:output text=\"please.confirm.deletion.of\"/>', \n this_cannot_be_undone: '<i18n:output text=\"this.cannot.be.undone\"/>' \n } \n }); \n </script> \n /*global NP_ArticleAdmin, jQuery, confirm */ \n NP_ArticleAdmin = function ($) { \n var text; \n\n function delete_article(event) { \n var article = $(this).parents(\"li.article\"), \n id = article.attr(\"id\"), \n name = article.find(\"h3.name\").html(); \n if (confirm(text.please_confirm_deletion_of + name + text.this_cannot_be_undone)) { \n $.post(\"/admin/delete_article\", {id: id}); \n article.fadeOut(); \n } \n event.preventDefault(); \n return false; \n } \n\n function initialize(data) { \n text = data.text; \n $(\"#articles a.delete\").click(delete_article); \n } \n\n return {initialize: initialize}; \n }(jQuery);\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229726",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12540/"
] |
229,747
|
<p>I have a button inside an updatepanel. I have a PopupControlExtender linked to the button so when the button is clicked a panel pops up. It works fine except it does a full postback and I can't figure out why. The button and the PopupControlExtender is inside an update panel which inside the ContentTemplate tag. When I take out the PopupControlExtender the button only does a partial postback. I'm having trouble finding any useful information on the PopupControlExtender. Do I have to declare a postback trigger or something?</p>
<p>Edit: If I use a LinkButton control it generates a partial postback. Seems to only do the full postback with a Button control.</p>
|
[
{
"answer_id": 9507971,
"author": "PeterX",
"author_id": 845584,
"author_profile": "https://Stackoverflow.com/users/845584",
"pm_score": 0,
"selected": false,
"text": "input.linkButton\n{\n background-color: transparent;\n border-style: none;\n color: #0000FF;\n cursor: pointer;\n text-align: left;\n text-decoration: underline; \n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18785/"
] |
229,756
|
<p>I'm relatively new to Python and am having problems programming with Scapy, the Python network manipulation tool. However, I can't tell if it's as much a Scapy problem as it is a being-a-Python-newbie problem. On the <a href="http://www.secdev.org/projects/scapy/build_your_own_tools.html" rel="noreferrer">scapy site</a>, they give a sample program which I'm not able to run on my own machine:</p>
<pre><code>#! /usr/bin/env python
import sys
from scapy import sr1,IP,ICMP
p=sr1(IP(dst=sys.argv[1])/ICMP())
if p:
p.show()
</code></pre>
<p>To which I get:</p>
<pre><code>Traceback (most recent call last):
File "test.py", line 4, in <module>
from scapy import sr1,IP,ICMP
ImportError: cannot import name sr1
</code></pre>
<p>So my question then is: when installing Python libraries, do I need to change my path or anything similar? Also, is there something I can run in the interpreter to tell me the contents of the scapy package? I can run <code>from scapy import *</code> just fine, but since I have no idea what's inside it, it's hard to use it.</p>
|
[
{
"answer_id": 229819,
"author": "ddaa",
"author_id": 11549,
"author_profile": "https://Stackoverflow.com/users/11549",
"pm_score": 4,
"selected": true,
"text": "PYTHONPATH /usr/lib/python2.5/site-packages PYTHONPATH >>> import scapy\n>>> dir(scapy)\n >>> import scapy\n>>> help(scapy)\n import scapy from scapy import *"
},
{
"answer_id": 229842,
"author": "kaleissin",
"author_id": 30368,
"author_profile": "https://Stackoverflow.com/users/30368",
"pm_score": 2,
"selected": false,
"text": ">>> import scapy\n>>> from pprint import pformat\n>>> pformat(dir(scapy))\n"
},
{
"answer_id": 230333,
"author": "Alex Coventry",
"author_id": 1941213,
"author_profile": "https://Stackoverflow.com/users/1941213",
"pm_score": 1,
"selected": false,
"text": "coventry@metta:~/src$ wget -q http://www.secdev.org/projects/scapy/files/scapy-latest.zip\ncoventry@metta:~/src$ unzip -qq scapy-latest.zip \nwarning [scapy-latest.zip]: 61 extra bytes at beginning or within zipfile\n (attempting to process anyway)\ncoventry@metta:~/src$ find scapy-2.0.0.10 -name \\*.py | xargs grep sr1\nscapy-2.0.0.10/scapy/layers/dns.py: r=sr1(IP(dst=nameserver)/UDP()/DNS(opcode=5,\nscapy-2.0.0.10/scapy/layers/dns.py: r=sr1(IP(dst=nameserver)/UDP()/DNS(opcode=5,\nscapy-2.0.0.10/scapy/layers/inet6.py:from scapy.sendrecv import sr,sr1,srp1\nscapy-2.0.0.10/scapy/layers/snmp.py: r = sr1(IP(dst=dst)/UDP(sport=RandShort())/SNMP(community=community, PDU=SNMPnext(varbindlist=[SNMPvarbind(oid=oid)])),timeout=2, chainCC=1, verbose=0, retry=2)\nscapy-2.0.0.10/scapy/layers/inet.py:from scapy.sendrecv import sr,sr1,srp1\nscapy-2.0.0.10/scapy/layers/inet.py: p = sr1(IP(dst=target, options=\"\\x00\"*40, proto=200)/\"XXXXYYYYYYYYYYYY\",timeout=timeout,verbose=0)\nscapy-2.0.0.10/scapy/sendrecv.py:def sr1(x,filter=None,iface=None, nofilter=0, *args,**kargs):\n sr1 scapy.sendrecv"
},
{
"answer_id": 942244,
"author": "Emilio",
"author_id": 39796,
"author_profile": "https://Stackoverflow.com/users/39796",
"pm_score": 2,
"selected": false,
"text": " from scapy.all import * \n from scapy import *\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/422/"
] |
229,763
|
<p>Is there a real way to get Netbeans to load and work faster?</p>
<p>It is too slow and gets worse when you have been coding for some time. It eats all my RAM.</p>
<hr>
<p>I am on a Windows machine, specifically Windows Server 2008 Datacenter Edition x64,
4Gb of RAM, 3Ghz Core 2 Duo processor, etc. I am using the x64 JDK. I use the NOD32 Antivirus since for me it is the best in machine performance.</p>
<p>In Task Manager netbeans.exe only shows no more than 20 Mb, java.exe more than 600Mb.</p>
<p>My project is a J2EE web application, more than 500 classes, only the project libraries not included (externals). And when I said slow, I mean 3, 4, 5 minutes or more Netbeans is frozen.</p>
<p>Is my project just too large for Netbeans, if it has to read all files to get the state of files like error warnings, svn status and more? Can I disable all this? Is it possible to set it to scan only when I open a file?</p>
<p>My CPU use is normally at 30 percent with all my tools opened, I mean Netbeans, MS SQL Manager, Notepad, XMLSpy, Task Manager, Delphi, VirtualBox. Netbeans eats more RAM than my virtualized systems.</p>
<p>In Linux it is as slow as in Windows in the same machine (Ubuntu 8.04 x64).</p>
<p>It is true that the Netbeans team improved startup speed but when it opens it begins to cache ALL. </p>
<p>I have used some JVM parameters to set high memory usage and others:
<code>"C:\Program Files\NetBeans Dev\bin\netbeans.exe" -J-Xms32m -J-Xmx512m -J-Xverify:none -J-XX:+CMSClassUnloadingEnabled</code></p>
<p>But it is still slow.</p>
|
[
{
"answer_id": 2425913,
"author": "schmunk",
"author_id": 291573,
"author_profile": "https://Stackoverflow.com/users/291573",
"pm_score": 2,
"selected": false,
"text": " sudo fs_usage | grep /path/to/workspace\n 14:08:05 getattrlist /path/to/workspaces/pii 0.000011 java\n ~/.netbeans/6.8/var/cache\n ~/.netbeans/VERSION/config/Preferences/org/netbeans/modules/versioning.properties \n unversionedFolders=FULL_PATH_TO_PROJECT_FOLDER \n"
},
{
"answer_id": 3750857,
"author": "atamanroman",
"author_id": 366299,
"author_profile": "https://Stackoverflow.com/users/366299",
"pm_score": 6,
"selected": false,
"text": "%AppData%"
},
{
"answer_id": 11390401,
"author": "shihabudheen",
"author_id": 1122272,
"author_profile": "https://Stackoverflow.com/users/1122272",
"pm_score": 4,
"selected": false,
"text": "-J-Xverify:none C:\\Program Files\\NetBeans <version>\\etc\\netbeans.conf -J-Xverify:none"
},
{
"answer_id": 15457666,
"author": "toha",
"author_id": 1084742,
"author_profile": "https://Stackoverflow.com/users/1084742",
"pm_score": 3,
"selected": false,
"text": "-J-Xmx1024m -J-Xms256m \"C:\\Program Files\\NetBeans 7.1\\bin\\netbeans.exe\" --jdkhome \"C:\\Program Files\\Java\\jdk1.6.0_10\" -J-Dorg.netbeans.modules.php.dbgp.level=400 -J-Xmx1024m -J-Xms256m\n etc Netbeans-Home netbeans.conf -Xms -Xmx # Note that default -Xmx and -XX:MaxPermSize are selected for you automatically.\n# You can find these values in var/log/messages.log file in your userdir.\n# The automatically selected value can be overridden by specifying -J-Xmx or\n# -J-XX:MaxPermSize= here or on the command line.\n netbeans_default_options=\"-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true -J-Dsun.awt.disableMixing=true -J-Dswing.aatext=true -J-Dawt.useSystemAAFontSettings=lcd --laf Nimbus\"\n Services.msc Startup Type Automatic Properties Manual Status"
},
{
"answer_id": 21473673,
"author": "J.G. te H.",
"author_id": 3256180,
"author_profile": "https://Stackoverflow.com/users/3256180",
"pm_score": 2,
"selected": false,
"text": "etc/netbeans.conf"
},
{
"answer_id": 27253694,
"author": "ollo",
"author_id": 1622894,
"author_profile": "https://Stackoverflow.com/users/1622894",
"pm_score": 2,
"selected": false,
"text": "etc/netbeans.conf swing.aatex"
},
{
"answer_id": 28935901,
"author": "Martin Zeitler",
"author_id": 549372,
"author_profile": "https://Stackoverflow.com/users/549372",
"pm_score": 1,
"selected": false,
"text": "run.args.extra=-J-DsvnClientAdapterFactory=commandline\n"
},
{
"answer_id": 32749396,
"author": "244an",
"author_id": 1526010,
"author_profile": "https://Stackoverflow.com/users/1526010",
"pm_score": 0,
"selected": false,
"text": "Tools -> Options -> Editor -> Hints"
},
{
"answer_id": 37949539,
"author": "ChrisVollo",
"author_id": 2395434,
"author_profile": "https://Stackoverflow.com/users/2395434",
"pm_score": 0,
"selected": false,
"text": "/Applications/NetBeans/NetBeans\\ 8.0.2.app/Contents/Resources/NetBeans/etc/netbeans.conf netbeans_default_options=\"-J-Dsun.java2d.opengl=true -J-Dsun.java2d.d3d=false -J-Xmx2048m ..."
},
{
"answer_id": 53596527,
"author": "sleeply4cat",
"author_id": 3258754,
"author_profile": "https://Stackoverflow.com/users/3258754",
"pm_score": 0,
"selected": false,
"text": "-J-Djavax.accessibility.assistive_technologies=\" \""
},
{
"answer_id": 65937790,
"author": "Francesco Galgani",
"author_id": 1277576,
"author_profile": "https://Stackoverflow.com/users/1277576",
"pm_score": 0,
"selected": false,
"text": "Tools -> Options -> Miscellaneous -> Rainbow"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30715/"
] |
229,765
|
<p>In cleaning up <a href="https://stackoverflow.com/questions/229447/how-to-create-a-two-sided-unique-index-on-two-fields#229521">this answer</a> I learnt a bit about <code>TRIGGER</code>s and stored procedures in MySQL, but was stunned that, while <code>BEFORE INSERT</code> and <code>BEFORE UPDATE</code> triggers could modify data, they seemingly couldn't cause the insert/update to fail (ie. validation). In this particular case I was able to get this to work by manipulating the data in such a way as to cause a primary key duplicate, which in this particular case made sense, but doesn't necessarily make sense in a general sense.</p>
<p>Is this sort of functionality possible in MySQL? In any other RDBMS (my experience is limited to MySQL sadly)? Perhaps a <code>THROW EXCEPTION</code> style syntax?</p>
|
[
{
"answer_id": 229802,
"author": "Esteban Brenes",
"author_id": 14177,
"author_profile": "https://Stackoverflow.com/users/14177",
"pm_score": 5,
"selected": true,
"text": "CREATE TRIGGER mytabletriggerexample\nBEFORE INSERT\nFOR EACH ROW BEGIN\nIF(NEW.important_value) < (fancy * dancy * calculation) THEN\n DECLARE dummy INT;\n\n SELECT Your meaningful error message goes here INTO dummy \n FROM mytable\n WHERE mytable.id=new.id\nEND IF; END;\n"
},
{
"answer_id": 229821,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 1,
"selected": false,
"text": "DROP PROCEDURE IF EXISTS `MyRaiseError`$$\n\nCREATE PROCEDURE `MyRaiseError`(msg VARCHAR(62))\nBEGIN\nDECLARE Tmsg VARCHAR(80);\nSET Tmsg = msg;\nIF (CHAR_LENGTH(TRIM(Tmsg)) = 0 OR Tmsg IS NULL) THEN\nSET Tmsg = 'ERROR GENERADO';\nEND IF;\nSET Tmsg = CONCAT('@@MyError', Tmsg, '@@MyError');\nSET @MyError = CONCAT('INSERT INTO', Tmsg);\nPREPARE stmt FROM @MyError;\nEXECUTE stmt;\nDEALLOCATE PREPARE stmt;\nEND$$\n call MyRaiseError('Here error message!');\n"
},
{
"answer_id": 229828,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": -1,
"selected": false,
"text": "IF UPDATE(column_name)\nBEGIN\n RAISEERROR\n ROLLBACK TRAN\n RETURN\nEND\n"
},
{
"answer_id": 2694100,
"author": "PCPGMR",
"author_id": 323650,
"author_profile": "https://Stackoverflow.com/users/323650",
"pm_score": 3,
"selected": false,
"text": "SET NEW='some error'; DELIMITER $$\nDROP TRIGGER IF EXISTS before_tblinventoryexceptionreasons_delete $$\nCREATE TRIGGER before_tblinventoryexceptionreasons_delete\nBEFORE DELETE ON tblinventoryexceptionreasons\nFOR EACH ROW BEGIN\n IF (SELECT COUNT(*) FROM tblinventoryexceptions WHERE tblinventoryexceptions.idtblinventoryexceptionreasons = old.idtblinventoryexceptionreasons) > 0\n THEN\n SET NEW='Error: Cannot delete this item. There are records in the inventory exception reasons table with this item.';\n END IF;\nEND$$\nDELIMITER ;\n\nDELIMITER $$\nDROP TRIGGER IF EXISTS before_storesalesconfig_delete $$\nCREATE TRIGGER before_storesalesconfig_delete\nBEFORE DELETE ON tblstoresalesconfig\nFOR EACH ROW BEGIN\n IF (SELECT COUNT(*) FROM tblstoresales WHERE tblstoresales.idtblstoresalesconfig=old.idtblstoresalesconfig) > 0\n THEN\n SET NEW='Error: Cannot delete this item. There are records in the sales table with this item.';\n END IF;\n IF (SELECT COUNT(*) FROM tblinventory WHERE tblinventory.idtblstoresalesconfig=old.idtblstoresalesconfig) > 0\n THEN\n SET NEW='Error: Cannot delete this item. There are records in the inventory table with this item.';\n END IF;\n IF (SELECT COUNT(*) FROM tblinventoryexceptions WHERE tblinventoryexceptions.idtblstoresalesconfig=old.idtblstoresalesconfig) > 0\n THEN\n SET NEW='Error: Cannot delete this item. There are records in the inventory exceptions table with this item.';\n END IF;\n IF (SELECT COUNT(*) FROM tblinvoicedetails WHERE tblinvoicedetails.idtblstoresalesconfig=old.idtblstoresalesconfig) > 0\n THEN\n SET NEW='Error: Cannot delete this item. There are records in the inventory details table with this item.';\n END IF;\nEND$$\nDELIMITER ;\n\nDELIMITER $$\nDROP TRIGGER IF EXISTS before_tblinvoice_delete $$\nCREATE TRIGGER before_tblinvoice_delete\nBEFORE DELETE ON tblinvoice\nFOR EACH ROW BEGIN\n IF (SELECT COUNT(*) FROM tblinvoicedetails WHERE tblinvoicedetails.idtblinvoice = old.idtblinvoice) > 0\n THEN\n SET NEW='Error: Cannot delete this item. There are records in the inventory details table with this item.';\n END IF;\nEND$$\nDELIMITER ;\n"
},
{
"answer_id": 11318648,
"author": "Karel Ruland",
"author_id": 1499915,
"author_profile": "https://Stackoverflow.com/users/1499915",
"pm_score": 1,
"selected": false,
"text": "If NEW.test=1 then\n CALL TEST_CANNOT_BE_SET_TO_1;\nend if;\n"
},
{
"answer_id": 26115231,
"author": "Kyle Johnson",
"author_id": 1733365,
"author_profile": "https://Stackoverflow.com/users/1733365",
"pm_score": 3,
"selected": false,
"text": "CREATE TRIGGER `my_table_AINS` AFTER INSERT ON `my_table` FOR EACH ROW\nBEGIN\n DECLARE EXIT HANDLER FOR SQLEXCEPTION\n RESIGNAL;\n DECLARE EXIT HANDLER FOR SQLWARNING\n RESIGNAL;\n DECLARE EXIT HANDLER FOR NOT FOUND\n RESIGNAL; \n -- Do the work of the trigger.\nEND\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229765",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
229,824
|
<p>Ok, there are a million regexes out there for validating an email address, but how about some basic email validation that can be integrated into a TSQL query for Sql Server 2005?</p>
<p>I don't want to use a CLR procedure or function. Just straight TSQL.</p>
<p>Has anybody tackled this already?</p>
|
[
{
"answer_id": 229955,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 7,
"selected": true,
"text": "SELECT\n EmailAddress, \n CASE WHEN EmailAddress LIKE '%_@_%_.__%' \n AND EmailAddress NOT LIKE '%[any obviously invalid characters]%' \n THEN 'Could be' \n ELSE 'Nope' \n END Validates\nFROM \n Table\n LIKE"
},
{
"answer_id": 1345539,
"author": "cabgef",
"author_id": 99999,
"author_profile": "https://Stackoverflow.com/users/99999",
"pm_score": 4,
"selected": false,
"text": "CREATE FUNCTION [dbo].[fnAppEmailCheck](@email VARCHAR(255)) \n--Returns true if the string is a valid email address. \nRETURNS bit \nas \nBEGIN \n DECLARE @valid bit \n IF @email IS NOT NULL \n SET @email = LOWER(@email) \n SET @valid = 0 \n IF @email like '[a-z,0-9,_,-]%@[a-z,0-9,_,-]%.[a-z][a-z]%' \n AND LEN(@email) = LEN(dbo.fnAppStripNonEmail(@email)) \n AND @email NOT like '%@%@%' \n AND CHARINDEX('.@',@email) = 0 \n AND CHARINDEX('..',@email) = 0 \n AND CHARINDEX(',',@email) = 0 \n AND RIGHT(@email,1) between 'a' AND 'z' \n SET @valid=1 \n RETURN @valid \nEND \n"
},
{
"answer_id": 2809784,
"author": "payonk",
"author_id": 338141,
"author_profile": "https://Stackoverflow.com/users/338141",
"pm_score": -1,
"selected": false,
"text": "select 1\nwhere @email not like '%[^a-z,0-9,@,.]%'\nand @email like '%_@_%_.__%'\n"
},
{
"answer_id": 25978991,
"author": "Mike Wallace",
"author_id": 4067421,
"author_profile": "https://Stackoverflow.com/users/4067421",
"pm_score": 0,
"selected": false,
"text": "Create Function [dbo].[fnAppStripNonEmail](@Temp VarChar(1000))\nReturns VarChar(1000)\nAS\nBegin\n\n Declare @KeepValues as varchar(50)\n Set @KeepValues = '%[^a-z,0-9,@,.,-]%'\n While PatIndex(@KeepValues, @Temp) > 0\n Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')\n\n Return @Temp\nEnd\n"
},
{
"answer_id": 28962448,
"author": "HamzeLue",
"author_id": 3104189,
"author_profile": "https://Stackoverflow.com/users/3104189",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM <TableName> WHERE [EMail] NOT LIKE '%_@__%.__%'\n"
},
{
"answer_id": 35160236,
"author": "Tony Dong",
"author_id": 760139,
"author_profile": "https://Stackoverflow.com/users/760139",
"pm_score": 1,
"selected": false,
"text": "Create Function [dbo].[fnAppStripNonEmail](@Temp VarChar(1000))\nReturns VarChar(1000)\nAS\nBegin\n\n Declare @KeepValues as varchar(50)\n Set @KeepValues = '%[^a-z,0-9,_,@,.,-]%'\n While PatIndex(@KeepValues, @Temp) > 0\n Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')\n\n Return @Temp\nEnd\n"
},
{
"answer_id": 37491215,
"author": "James",
"author_id": 1887946,
"author_profile": "https://Stackoverflow.com/users/1887946",
"pm_score": 2,
"selected": false,
"text": "CREATE FUNCTION [dbo].[fnIsValidEmail]\n(\n @email varchar(255)\n) \n--Returns true if the string is a valid email address. \nRETURNS bit \nAs \nBEGIN\n RETURN CASE WHEN ISNULL(@email, '') <> '' AND @email LIKE '%_@%_.__%' THEN 1 ELSE 0 END\nEND\n"
},
{
"answer_id": 43589857,
"author": "Roy Gelerman",
"author_id": 7914057,
"author_profile": "https://Stackoverflow.com/users/7914057",
"pm_score": 1,
"selected": false,
"text": "CREATE FUNCTION fnIsValidEmail\n(\n @email varchar(255)\n)\nRETURNS bit\nAS\nBEGIN\n\n DECLARE @IsValidEmail bit = 0\n\n IF (@email not like '%[^a-z,0-9,@,.,!,#,$,%%,&,'',*,+,--,/,=,?,^,_,`,{,|,},~]%' --First Carat ^ means Not these characters in the LIKE clause. The list is the valid email characters.\n AND @email like '%_@_%_.[a-z,0-9][a-z]%'\n AND @email NOT like '%@%@%' \n AND @email NOT like '%..%'\n AND @email NOT like '.%'\n AND @email NOT like '%.'\n AND CHARINDEX('@', @email) <= 65\n )\n BEGIN\n SET @IsValidEmail = 1\n END\n\n RETURN @IsValidEmail\n\nEND\n"
},
{
"answer_id": 47350807,
"author": "Esperento57",
"author_id": 3735690,
"author_profile": "https://Stackoverflow.com/users/3735690",
"pm_score": 2,
"selected": false,
"text": "CREATE FUNCTION [DBO].[F_IsEmail] (\n @EmailAddr varchar(360) -- Email address to check\n) RETURNS BIT -- 1 if @EmailAddr is a valid email address\n\nAS BEGIN\nDECLARE @AlphabetPlus VARCHAR(255)\n , @Max INT -- Length of the address\n , @Pos INT -- Position in @EmailAddr\n , @OK BIT -- Is @EmailAddr OK\n-- Check basic conditions\nIF @EmailAddr IS NULL \n OR @EmailAddr NOT LIKE '[0-9a-zA-Z]%@__%.__%' \n OR @EmailAddr LIKE '%@%@%' \n OR @EmailAddr LIKE '%..%' \n OR @EmailAddr LIKE '%.@' \n OR @EmailAddr LIKE '%@.' \n OR @EmailAddr LIKE '%@%.-%' \n OR @EmailAddr LIKE '%@%-.%' \n OR @EmailAddr LIKE '%@-%' \n OR CHARINDEX(' ',LTRIM(RTRIM(@EmailAddr))) > 0\n RETURN(0)\n\n\n\ndeclare @AfterLastDot varchar(360);\ndeclare @AfterArobase varchar(360);\ndeclare @BeforeArobase varchar(360);\ndeclare @HasDomainTooLong bit=0;\n\n--Control des longueurs et autres incoherence\nset @AfterLastDot=REVERSE(SUBSTRING(REVERSE(@EmailAddr),0,CHARINDEX('.',REVERSE(@EmailAddr))));\nif len(@AfterLastDot) not between 2 and 17\nRETURN(0);\n\nset @AfterArobase=REVERSE(SUBSTRING(REVERSE(@EmailAddr),0,CHARINDEX('@',REVERSE(@EmailAddr))));\nif len(@AfterArobase) not between 2 and 255\nRETURN(0);\n\nselect top 1 @BeforeArobase=value from string_split(@EmailAddr, '@');\nif len(@AfterArobase) not between 2 and 255\nRETURN(0);\n\n--Controle sous-domain pas plus grand que 63\nselect top 1 @HasDomainTooLong=1 from string_split(@AfterArobase, '.') where LEN(value)>63\nif @HasDomainTooLong=1\nreturn(0);\n\n--Control de la partie locale en detail\nSELECT @AlphabetPlus = 'abcdefghijklmnopqrstuvwxyz01234567890!#$%&‘*+-/=?^_`.{|}~'\n , @Max = LEN(@BeforeArobase)\n , @Pos = 0\n , @OK = 1\n\n\nWHILE @Pos < @Max AND @OK = 1 BEGIN\n SET @Pos = @Pos + 1\n IF @AlphabetPlus NOT LIKE '%' + SUBSTRING(@BeforeArobase, @Pos, 1) + '%' \n SET @OK = 0\nEND\n\nif @OK=0\nRETURN(0);\n\n--Control de la partie domaine en detail\nSELECT @AlphabetPlus = 'abcdefghijklmnopqrstuvwxyz01234567890-.'\n , @Max = LEN(@AfterArobase)\n , @Pos = 0\n , @OK = 1\n\nWHILE @Pos < @Max AND @OK = 1 BEGIN\n SET @Pos = @Pos + 1\n IF @AlphabetPlus NOT LIKE '%' + SUBSTRING(@AfterArobase, @Pos, 1) + '%' \n SET @OK = 0\nEND\n\nif @OK=0\nRETURN(0);\n\n\n\n\n\n\n\nreturn(1);\n\n\n\nEND\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1219/"
] |
229,831
|
<p>I'm trying to create a form that has an expandable widget. The problem is that when the widget is open, The form extends outside the limit in the content box, and it looks bad.</p>
<p>I tried using <code>overflow:scroll</code> but it creates 2 ugly scrollbars that do not disappear even if the content is smaller then the content box. I only need one vertical scrollbar.</p>
<p>Visual Studio also alerted that overflow-y is not available in CSS.</p>
|
[
{
"answer_id": 229838,
"author": "swilliams",
"author_id": 736,
"author_profile": "https://Stackoverflow.com/users/736",
"pm_score": 5,
"selected": true,
"text": "auto"
},
{
"answer_id": 230027,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 2,
"selected": false,
"text": "overflow-x overflow-y overflow: auto;\noverflow-x: auto;\noverflow-y: auto;\n overflow: auto overflow: scroll overflow-x overflow-y"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229831",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
229,856
|
<p>What is the best way to save enums into a database?</p>
<p>I know Java provides <code>name()</code> and <code>valueOf()</code> methods to convert enum values into a String and back. But are there any other (flexible) options to store these values?</p>
<p>Is there a smart way to make enums into unique numbers (<code>ordinal()</code> is not safe to use)?</p>
<h4>Update</h4>
<p>Thanks for all awesome and fast answers! It was as I suspected.</p>
<p>However, a note to <a href="https://stackoverflow.com/users/3295">toolkit</a>: That is one way. The problem is that I would have to add the same methods to each enum type that I create. That's a lot of duplicated code and, at the moment, Java does not support any solutions for this (a Java enum cannot extend other classes).</p>
|
[
{
"answer_id": 229902,
"author": "oxbow_lakes",
"author_id": 16853,
"author_profile": "https://Stackoverflow.com/users/16853",
"pm_score": 3,
"selected": false,
"text": "name()"
},
{
"answer_id": 229919,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 9,
"selected": true,
"text": "public enum Suit { Spade, Heart, Diamond, Club }\n\nSuit theSuit = Suit.Heart;\n\nszQuery = \"INSERT INTO Customers (Name, Suit) \" +\n \"VALUES ('Ian Boyd', %s)\".format(theSuit.name());\n Suit theSuit = Suit.valueOf(reader[\"Suit\"]);\n Name Suit\n------------ ----\nKylie Guénin 2\nIan Boyd 1\n Name Suit\n------------ -------\nKylie Guénin Diamond\nIan Boyd Heart\n public enum Suit { Unknown, Heart, Club, Diamond, Spade }\n public enum Suit { \n Unknown = 4,\n Heart = 1,\n Club = 3,\n Diamond = 2,\n Spade = 0 }\n enum SELECT Suit FROM Cards\nORDER BY SuitID; --where SuitID is integer value(4,1,3,2,0)\n\nSuit\n------\nSpade\nHeart\nDiamond\nClub\nUnknown\n SELECT Suit FROM Cards\nORDER BY CASE SuitID OF\n WHEN 4 THEN 0 --Unknown first\n WHEN 1 THEN 1 --Heart\n WHEN 3 THEN 2 --Club\n WHEN 2 THEN 3 --Diamond\n WHEN 0 THEN 4 --Spade\n ELSE 999 END\n SELECT Suit FROM Cards\nORDER BY Suit; --where Suit is an enum name\n\nSuit\n-------\nClub\nDiamond\nHeart\nSpade\nUnknown\n SELECT Suit FROM Cards\nORDER BY CASE Suit OF\n WHEN 'Unknown' THEN 0\n WHEN 'Heart' THEN 1\n WHEN 'Club' THEN 2\n WHEN 'Diamond' THEN 3\n WHEN 'Space' THEN 4\n ELSE 999 END\n Suits SELECT Cards.Suit \nFROM Cards\n INNER JOIN Suits ON Cards.Suit = Suits.Suit\nORDER BY Suits.Rank, \n Card.Rank*Suits.CardOrder\n \n"
},
{
"answer_id": 229936,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 3,
"selected": false,
"text": "public enum Boolean {\n TRUE, FALSE\n}\n\npublic class BooleanTest {\n @Test\n public void testEnum() {\n assertEquals(0, Boolean.TRUE.ordinal());\n assertEquals(1, Boolean.FALSE.ordinal());\n }\n}\n > SELECT STATEMENT, TRUTH FROM CALL_MY_BLUFF\n\n\"Alice is a boy\" 1\n\"Graham is a boy\" 0\n public enum Boolean {\n TRUE, FILE_NOT_FOUND, FALSE\n}\n"
},
{
"answer_id": 230000,
"author": "JeeBee",
"author_id": 17832,
"author_profile": "https://Stackoverflow.com/users/17832",
"pm_score": 3,
"selected": false,
"text": "char char public enum EmailStatus {\n EMAIL_NEW('N'), EMAIL_SENT('S'), EMAIL_FAILED('F'), EMAIL_SKIPPED('K'), UNDEFINED('-');\n\n private char dbChar = '-';\n\n EmailStatus(char statusChar) {\n this.dbChar = statusChar;\n }\n\n public char statusChar() {\n return dbChar;\n }\n\n public static EmailStatus getFromStatusChar(char statusChar) {\n switch (statusChar) {\n case 'N':\n return EMAIL_NEW;\n case 'S':\n return EMAIL_SENT;\n case 'F':\n return EMAIL_FAILED;\n case 'K':\n return EMAIL_SKIPPED;\n default:\n return UNDEFINED;\n }\n }\n}\n Map getFromXYZ"
},
{
"answer_id": 230088,
"author": "Roger Durham",
"author_id": 29760,
"author_profile": "https://Stackoverflow.com/users/29760",
"pm_score": 2,
"selected": false,
"text": "SELECT reftable.* FROM reftable\n LEFT JOIN enumtable ON reftable.enum_ref_id = enumtable.enum_id\nWHERE enumtable.enum_id IS NULL;\n"
},
{
"answer_id": 230756,
"author": "Dov Wasserman",
"author_id": 26010,
"author_profile": "https://Stackoverflow.com/users/26010",
"pm_score": 2,
"selected": false,
"text": " public static String getSerializedForm(Enum<?> enumVal) {\n String name = enumVal.name();\n // possibly quote value?\n return name;\n }\n\n public static <E extends Enum<E>> E deserialize(Class<E> enumType, String dbVal) {\n // possibly handle unknown values, below throws IllegalArgEx\n return Enum.valueOf(enumType, dbVal.trim());\n }\n\n // Sample use:\n String dbVal = getSerializedForm(Suit.SPADE);\n // save dbVal to db in larger insert/update ...\n Suit suit = deserialize(Suit.class, dbVal);\n"
},
{
"answer_id": 415595,
"author": "Tom",
"author_id": 40620,
"author_profile": "https://Stackoverflow.com/users/40620",
"pm_score": 6,
"selected": false,
"text": "suit_id suit_name\n1 Clubs\n2 Hearts\n3 Spades\n4 Diamonds\n player_name suit_id\nIan Boyd 4\nShelby Lake 2\n suit_id"
},
{
"answer_id": 31329990,
"author": "Metaphore",
"author_id": 3802890,
"author_profile": "https://Stackoverflow.com/users/3802890",
"pm_score": 2,
"selected": false,
"text": "enum Race {\n HUMAN (\"human\"),\n ELF (\"elf\"),\n DWARF (\"dwarf\");\n\n private final String code;\n\n private Race(String code) {\n this.code = code;\n }\n\n public String getCode() {\n return code;\n }\n}\n DWARF(\"dwarf\") GNOME(\"dwarf\") interface CodeValue {\n String getCode();\n}\n enum Race implement CodeValue {...}\n static <T extends Enum & CodeValue> T resolveByCode(Class<T> enumClass, String code) {\n T[] enumConstants = enumClass.getEnumConstants();\n for (T entry : enumConstants) {\n if (entry.getCode().equals(code)) return entry;\n }\n // In case we failed to find it, return null.\n // I'd recommend you make some log record here to get notified about wrong logic, perhaps.\n return null;\n}\n Race race = resolveByCode(Race.class, \"elf\")"
},
{
"answer_id": 37473149,
"author": "SaravanaC",
"author_id": 6328496,
"author_profile": "https://Stackoverflow.com/users/6328496",
"pm_score": 3,
"selected": false,
"text": "@Enumerated(EnumType.STRING) Enum public enum FurthitMethod {\n\n Apple,\n Orange,\n Lemon\n}\n @Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)\n@Column(name = \"Fruits\")\npublic FurthitMethod getFuritMethod() {\n return fruitMethod;\n}\n\npublic void setFruitMethod(FurthitMethod authenticationMethod) {\n this.fruitMethod= fruitMethod;\n}\n APPLE ORANGE LEMON"
},
{
"answer_id": 59575547,
"author": "Erk",
"author_id": 386587,
"author_profile": "https://Stackoverflow.com/users/386587",
"pm_score": 0,
"selected": false,
"text": "public enum MyEnum {\n MyFirstValue(10),\n MyFirstAndAHalfValue(15),\n MySecondValue(20);\n\n public int getId() {\n return id;\n }\n public static MyEnum of(int id) {\n for (MyEnum e : values()) {\n if (id == e.id) {\n return e;\n }\n }\n return null;\n }\n MyEnum(int id) {\n this.id = id;\n }\n private final int id;\n}\n int id = MyFirstValue.getId();\n MyEnum e = MyEnum.of(id);\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20298/"
] |
229,865
|
<p>I have some simple .doc files I made in Word 2007 where I changed the text color and used highlights to compare some similar texts. What I'd like to do is change any instances of green text or gray highlighting to different respective colors for each.</p>
<p>I'm sure there is a simple way to do this with VBA but any other sort of answers are also welcome.</p>
<p>EDIT: While I do appreciate answers, one that allows me to keep the .doc files as .docs is preferred.</p>
|
[
{
"answer_id": 230305,
"author": "buti-oxa",
"author_id": 2515,
"author_profile": "https://Stackoverflow.com/users/2515",
"pm_score": 1,
"selected": false,
"text": "<span style='color:red'>...\n <span style='background:yellow;mso-highlight:yellow'>...\n"
},
{
"answer_id": 231736,
"author": "Fionnuala",
"author_id": 2548,
"author_profile": "https://Stackoverflow.com/users/2548",
"pm_score": 2,
"selected": false,
"text": "Sub ChangeColor\nOptions.DefaultHighlightColorIndex = wdBrightGreen\n\n Selection.Find.ClearFormatting\n Selection.Find.Highlight = True\n Selection.Find.Replacement.ClearFormatting\n Selection.Find.Replacement.Highlight = True\n Selection.Find.Execute Replace:=wdReplaceAll\n\n Selection.Find.ClearFormatting\n Selection.Find.Font.Color = wdColorBrightGreen\n Selection.Find.Replacement.ClearFormatting\n Selection.Find.Replacement.Font.Color = wdColorRed\n With Selection.Find\n .Text = \"\"\n .Replacement.Text = \"\"\n .Forward = True\n .Wrap = wdFindContinue\n End With\n Selection.Find.Execute Replace:=wdReplaceAll\nEnd Sub\n"
},
{
"answer_id": 595442,
"author": "guillermooo",
"author_id": 1670,
"author_profile": "https://Stackoverflow.com/users/1670",
"pm_score": 0,
"selected": false,
"text": "Sub RehiliteAll()\n\n Const YOUR_REQUIRED_COLOR_IDX As Integer = 6 'RED'\n Dim doc As Range\n Set doc = ActiveDocument.Range\n\n With doc.Find\n .ClearFormatting 'resets default search options'\n .Highlight = True\n .Wrap = wdFindStop\n\n While .Execute\n\n If doc.HighlightColorIndex = YOUR_REQUIRED_COLOR_IDX Then\n doc.Select\n MsgBox doc.HighlightColorIndex\n 'Do stuff here'\n End If\n\n 'doc has been reassigned to the matching'\n 'range; we do this so word keeps searching'\n 'forward'\n doc.Collapse wdCollapseEnd\n Wend\n End With\n\n Set doc = Nothing\nEnd Sub\n\n'I am closing comment quotes so that SO formatting'\n'does not get messed up too much.'\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25680/"
] |
229,870
|
<p>I have a gridview containing some data from db, and after a check I want to see a small cross/tick image in each row, due to the result of the check.How can I change the image url dynamically? </p>
|
[
{
"answer_id": 251638,
"author": "gfrizzle",
"author_id": 23935,
"author_profile": "https://Stackoverflow.com/users/23935",
"pm_score": 0,
"selected": false,
"text": "<Columns>\n <asp:TemplateField>\n <ItemTemplate>\n <asp:Image ID=\"check\" runat=\"server\" ImageUrl='<%#If(Eval(\"check\") = 1,\"images/checked.gif\",\"images/unchceked.gif\") %>' />\n </ItemTemplate>\n </asp:TemplateField>\n</Columns>\n"
},
{
"answer_id": 3689654,
"author": "Chinjoo",
"author_id": 356061,
"author_profile": "https://Stackoverflow.com/users/356061",
"pm_score": 2,
"selected": false,
"text": "<%#Eval(\"check\").ToString() == \"1\" ? \"images/checked.gif\" : \"images/unchceked.gif\")%> <%# getImageUrl(Eval(\"value\")) %>\nPublic Function getImageUrl(ByVal value As Integer) As String\n If value = 0 Then\n Return \"images/unchceked.gif\"\n Else\n Return \"mages/checked.gif\"\n End If\nEnd Function\n"
},
{
"answer_id": 4539324,
"author": "Beytan Kurt",
"author_id": 284420,
"author_profile": "https://Stackoverflow.com/users/284420",
"pm_score": 0,
"selected": false,
"text": "<Columns>\n <asp:TemplateField>\n <ItemTemplate>\n <asp:ImageButton ID=\"check\" runat=\"server\" ImageUrl='<%# GetImageUrl(Eval(\"Check\")) %>' />\n </ItemTemplate>\n </asp:TemplateField>\n</Columns>\n public string GetImageUrl(object checkObject)\n{\n if (checkObject!= null)\n {\n bool check;\n bool parsable = bool.Parse(checkObject.ToString(), out check);\n check= parsable ? check : false;\n\n return check ? \"~/Media/Images/tick.png\" : \"~/Media/Images/untick.png\";\n }\n\n return \"~/Media/Images/none.png\";\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229870",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
229,883
|
<p>Anyone point my at a utility for syncing sql server logins after restoring a database to a different server? </p>
<p>I know I can do it with scripts, but I've been using a wonderful little utility - 'Db Maint Sync SQL Logins' (<a href="http://www.dbmaint.com/SyncSqlLogins.asp" rel="nofollow noreferrer">http://www.dbmaint.com/SyncSqlLogins.asp</a>) to do it on sql server 2000 which unfortunately doesn't support 2005 and I'm loath to go back to actually thinking :-)</p>
|
[
{
"answer_id": 229980,
"author": "PhilPursglove",
"author_id": 1738,
"author_profile": "https://Stackoverflow.com/users/1738",
"pm_score": 2,
"selected": true,
"text": "sp_change_users_login Update_One"
},
{
"answer_id": 243557,
"author": "GilaMonster",
"author_id": 9342,
"author_profile": "https://Stackoverflow.com/users/9342",
"pm_score": 1,
"selected": false,
"text": "sp_change_users_login"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7315/"
] |
229,886
|
<p>I have heard mixed opinions over the amount of memory that a byte takes up in a java program.</p>
<p>I am aware you can store no more than +127 in a java byte, and the <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html" rel="noreferrer">documentation</a> says that a byte is only 8 bits but <a href="http://www.jguru.com/faq/view.jsp?EID=13647" rel="noreferrer">here</a> I am told that it actually takes up the same amount of memory as an int, and therefore is just a Type that helps in code comprehension and not efficiency. </p>
<p>Can anyone clear this up, and would this be an implementation specific issue?</p>
|
[
{
"answer_id": 230063,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": true,
"text": "class LotsOfBytes\n{\n byte a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af;\n byte b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf;\n byte c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf;\n byte d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, da, db, dc, dd, de, df;\n byte e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, ea, eb, ec, ed, ee, ef;\n}\n\nclass LotsOfInts\n{\n int a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af;\n int b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf;\n int c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf;\n int d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, da, db, dc, dd, de, df;\n int e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, ea, eb, ec, ed, ee, ef;\n}\n\n\npublic class Test\n{\n private static final int SIZE = 1000000;\n\n public static void main(String[] args) throws Exception\n { \n LotsOfBytes[] first = new LotsOfBytes[SIZE];\n LotsOfInts[] second = new LotsOfInts[SIZE];\n\n System.gc();\n long startMem = getMemory();\n\n for (int i=0; i < SIZE; i++)\n {\n first[i] = new LotsOfBytes();\n }\n\n System.gc();\n long endMem = getMemory();\n\n System.out.println (\"Size for LotsOfBytes: \" + (endMem-startMem));\n System.out.println (\"Average size: \" + ((endMem-startMem) / ((double)SIZE)));\n\n System.gc();\n startMem = getMemory();\n for (int i=0; i < SIZE; i++)\n {\n second[i] = new LotsOfInts();\n }\n System.gc();\n endMem = getMemory();\n\n System.out.println (\"Size for LotsOfInts: \" + (endMem-startMem));\n System.out.println (\"Average size: \" + ((endMem-startMem) / ((double)SIZE)));\n\n // Make sure nothing gets collected\n long total = 0;\n for (int i=0; i < SIZE; i++)\n {\n total += first[i].a0 + second[i].a0;\n }\n System.out.println(total);\n }\n\n private static long getMemory()\n {\n Runtime runtime = Runtime.getRuntime();\n return runtime.totalMemory() - runtime.freeMemory();\n }\n}\n Size for LotsOfBytes: 88811688\nAverage size: 88.811688\nSize for LotsOfInts: 327076360\nAverage size: 327.07636\n0\n"
},
{
"answer_id": 11879948,
"author": "Unai Vivi",
"author_id": 1018783,
"author_profile": "https://Stackoverflow.com/users/1018783",
"pm_score": 0,
"selected": false,
"text": "byte B=(byte)200;//B contains 200\nSystem.out.println((B+256)%256);//Prints 200\nSystem.out.println(B&0xFF);//Prints 200\n"
},
{
"answer_id": 13898807,
"author": "Fuad Efendi",
"author_id": 1748983,
"author_profile": "https://Stackoverflow.com/users/1748983",
"pm_score": 3,
"selected": false,
"text": "byte: 16 bytes,\n int: 16 bytes,\nlong: 24 bytes.\n byte[1]: 24 bytes\n int[1]: 24 bytes\nlong[1]: 24 bytes\n\nbyte[2]: 24 bytes\n int[2]: 24 bytes\nlong[2]: 32 bytes\n\nbyte[4]: 24 bytes\n int[4]: 32 bytes\nlong[4]: 48 bytes\n\nbyte[8]: 24 bytes => 8 bytes, \"start\" address, \"end\" address => 8 + 8 + 8 bytes\n int[8]: 48 bytes => 8 integers (4 bytes each), \"start\" address, \"end\" address => 8*4 + 8 + 8 bytes\nlong[8]: 80 bytes => 8 longs (8 bytes each), \"start\" address, \"end\" address => 8x8 + 8 + 8 bytes\n byte[8]: 24 bytes\n byte[1][8]: 48 bytes\n byte[64]: 80 bytes\n byte[8][8]: 240 bytes\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29924/"
] |
229,887
|
<p>Can a flash front end talk to a .net backend?</p>
|
[
{
"answer_id": 229901,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 3,
"selected": false,
"text": "<mx:WebService id=\"myDataService\" showBusyCursor=\"true\">\n <mx:operation name=\"WebMethodName\" resultFormat=\"object\" result=\"functionFiredOnComplete();\"></mx:operation>\n</mx:WebService>\n\npublic function load():void\n{\n myDataService.loadWSDL( \"web method's wsdl\" );\n myDataService.WebMethodName.send( params );\n}\n\npublic function functionFiredOnComplete():void\n{ \n // get data\n var myData:Object = myDataService.WebMethodName.lastResult;\n ...\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
229,889
|
<p>What are the dangerous characters that should be replaced in user input when the users' input will be inserted in a MySQL query? I know about quotes, double quotes, \r and \n. Are there others?<br><sub>(I don't have the option of using a smart connector that accepts parameters so I have to build the query myself and this will be implemented in multiple programming languages, including some obscure ones so solutions such as <code>mysql_real_escape_string</code> in PHP are not valid)</sub></p>
|
[
{
"answer_id": 229941,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 2,
"selected": false,
"text": "mysql_real_escape_string mysql_real_escape_string() mysql_real_escape_string \\x00 \\n \\r \\ ' \" \\x1a"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229889",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26155/"
] |
229,890
|
<p>Let me begin with an illustrative example (assume the implementation is in a statically typed language such as Java or C#).</p>
<p>Assume that you are building a content management system (CMS) or something similar. The data is hierarchically organised into <code>Folder</code>s. Each folder has a collection of children; a child may be a <code>Page</code> or a <code>Folder</code>. All items are stored within a root folder. No cycles are allowed. We have an acyclic graph.</p>
<p>The system will have a remote API and instances of <code>Folder</code> and <code>Page</code> must be serialized / de-serialized across the network. With a typical implementation of folder, in which a folder's children are a <code>List</code>, serialization of the root node would send the entire graph. This is unacceptable for obvious reasons.</p>
<p>I am interested to hear people have solved this problem in the past.</p>
<p>I have two potential suggestions:</p>
<ol>
<li><strong>Navigation by query</strong>: Change the domain model so that the folder class contains only a list of IDs for each child. To access a child we must query for it. Serialisation is now trivial since the graph ends at a well defined point. The major downside is that we lose type safety - the ID could be for something other than a folder/child.</li>
<li><strong>Stop and re-attach</strong>: During serialization stop whenever we detect a reference to a folder or page, send the ID instead. When de-serializing we must then look up the corresponding object for each ID and re-attach it at the relevant position in the nascent object.</li>
</ol>
|
[
{
"answer_id": 992926,
"author": "Chris Vest",
"author_id": 13251,
"author_profile": "https://Stackoverflow.com/users/13251",
"pm_score": 1,
"selected": false,
"text": "Folder"
},
{
"answer_id": 1217325,
"author": "djna",
"author_id": 82511,
"author_profile": "https://Stackoverflow.com/users/82511",
"pm_score": 0,
"selected": false,
"text": "canHaveChildren() \ngetChildren() \n getChildren()"
},
{
"answer_id": 3545165,
"author": "Unmesh Kondolikar",
"author_id": 393877,
"author_profile": "https://Stackoverflow.com/users/393877",
"pm_score": 0,
"selected": false,
"text": "FolderBowser"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27929/"
] |
229,924
|
<p>What translation occurs when writing to a file that was opened in text mode that does not occur in binary mode? Specifically in MS Visual C.</p>
<pre><code>unsigned char buffer[256];
for (int i = 0; i < 256; i++) buffer[i]=i;
int size = 1;
int count = 256;
</code></pre>
<p>Binary mode:</p>
<pre><code>FILE *fp_binary = fopen(filename, "wb");
fwrite(buffer, size, count, fp_binary);
</code></pre>
<p>Versus text mode:</p>
<pre><code>FILE *fp_text = fopen(filename, "wt");
fwrite(buffer, size, count, fp_text);
</code></pre>
|
[
{
"answer_id": 230655,
"author": "Richard Corden",
"author_id": 11698,
"author_profile": "https://Stackoverflow.com/users/11698",
"pm_score": 2,
"selected": false,
"text": "1\\n\\r\n2\\n\\r\n3\\n\n4\\n\\r\n5\\n\\r\n"
},
{
"answer_id": 24798837,
"author": "Ming",
"author_id": 2021245,
"author_profile": "https://Stackoverflow.com/users/2021245",
"pm_score": 3,
"selected": false,
"text": "fseek"
},
{
"answer_id": 64306464,
"author": "David Lopez",
"author_id": 4044001,
"author_profile": "https://Stackoverflow.com/users/4044001",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n\nint main() {\n FILE *f;\n char string[] = \"A\\nB\";\n int len;\n \n len = strlen(string);\n printf(\"As you'd expect string has %d characters... \", len); /* prints 3*/\n f = fopen(\"test.txt\", \"w\"); /* Text mode */\n fwrite(string, 1, len, f); /* On windows \"A\\r\\nB\" is writen */\n printf (\"but %ld bytes were writen to file\", ftell(f)); /* prints 4 on Windows, 3 on Linux*/ \n fclose(f);\n return 0;\n}\n As you'd expect string has 3 characters... but 4 bytes were writen to file\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5065/"
] |
229,925
|
<p>Using the following code I get a nice formatted string:</p>
<pre><code>Request.QueryString.ToString
</code></pre>
<p>Gives me something like: &hello=world&microsoft=sucks</p>
<p>But when I use this code to clone the collection to another object (of the same type) I get the Type() back from the ToString() method instead.</p>
<pre><code>System.Collections.Specialized.NameValueCollection variables = new System.Collections.Specialized.NameValueCollection(Request.QueryString);
if (!string.IsNullOrEmpty(variables["sid"]))
variables.Remove("sid");
Response.Write(variables.ToString());
</code></pre>
<p>Is there a tidier way to output it rather than looking and building the string manually?</p>
|
[
{
"answer_id": 229964,
"author": "Johannes Hädrich",
"author_id": 18246,
"author_profile": "https://Stackoverflow.com/users/18246",
"pm_score": 2,
"selected": false,
"text": " if (!string.IsNullOrEmpty(Request.QueryString[\"sid\"]))\n Request.QueryString.Remove(\"sid\");\n System.Collections.Specialized.NameValueCollection variables = new System.Collections.Specialized.NameValueCollection(Request.QueryString);\nif (!string.IsNullOrEmpty(variables[\"sid\"]))\n variables.Remove(\"sid\");\n"
},
{
"answer_id": 229991,
"author": "Igal Tabachnik",
"author_id": 8205,
"author_profile": "https://Stackoverflow.com/users/8205",
"pm_score": 4,
"selected": true,
"text": "HttpValueCollection"
},
{
"answer_id": 230092,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 1,
"selected": false,
"text": "var variables = Request.QueryString.OfType<DictionaryEntry>()\n .Where(entry => entry.Key != \"sid\")\n .ToDictionary(entry => entry.Key, entry => entry.Value);\n"
},
{
"answer_id": 1425729,
"author": "Michele Bersini",
"author_id": 173568,
"author_profile": "https://Stackoverflow.com/users/173568",
"pm_score": 6,
"selected": false,
"text": "var query = HttpUtility.ParseQueryString(Request.Url.Query);\nquery[\"Lang\"] = myLanguage; // Add or replace param\nstring myNewUrl = Request.Url.AbsolutePath + \"?\" + query;\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/258/"
] |
229,935
|
<p>OK, first for context look at the Windows desktop; You can take items (folders, files) on the desktop and drag them around to different places and they "stay" where you dragged them. This seems to be a pretty useful feature to offer users so as to allow them to create their own "groupings" of items.</p>
<p>My question is thus:
Is there a control in .NET that approximates this behavior with a collection of items?</p>
<p>I'm thinking something like a listview in "LargeIcon" mode, but it allows you to drag the icons around to different places inside the control.</p>
|
[
{
"answer_id": 231486,
"author": "Hans Passant",
"author_id": 17034,
"author_profile": "https://Stackoverflow.com/users/17034",
"pm_score": 4,
"selected": true,
"text": "using System;\nusing System.Drawing;\nusing System.Windows.Forms;\n\npublic class MyListView : ListView {\n private Point mItemStartPos;\n private Point mMouseStartPos;\n\n public MyListView() {\n this.AllowDrop = true;\n this.View = View.LargeIcon;\n this.AutoArrange = false;\n this.DoubleBuffered = true;\n }\n\n protected override void OnDragEnter(DragEventArgs e) {\n if (e.Data.GetData(typeof(ListViewItem)) != null) e.Effect = DragDropEffects.Move;\n }\n protected override void OnItemDrag(ItemDragEventArgs e) {\n // Start dragging\n ListViewItem item = e.Item as ListViewItem;\n mItemStartPos = item.Position;\n mMouseStartPos = Control.MousePosition;\n this.DoDragDrop(item, DragDropEffects.Move);\n }\n protected override void OnDragOver(DragEventArgs e) {\n // Move icon\n ListViewItem item = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;\n if (item != null) {\n Point mousePos = Control.MousePosition;\n item.Position = new Point(mItemStartPos.X + mousePos.X - mMouseStartPos.X,\n mItemStartPos.Y + mousePos.Y - mMouseStartPos.Y);\n }\n }\n}\n"
},
{
"answer_id": 37005844,
"author": "Ledom",
"author_id": 5098871,
"author_profile": "https://Stackoverflow.com/users/5098871",
"pm_score": 0,
"selected": false,
"text": "ListView32 <icons>\n <icon1>\n <name>Icon1</name>\n <text>My PC</text>\n <imageIndex>16</imageIndex>\n </icon1>\n <icon2>\n .....\n </icon2> \n .....\n</icons>\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229935",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13776/"
] |
229,937
|
<p>Is it possible to use <code>request.setAttribute</code> on a JSP page and then on HTML Submit get the same request attribute in the <code>Servlet</code>?</p>
|
[
{
"answer_id": 229957,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "<input type=\"hidden\" name=\"myhiddenvalue\" value=\"<%= request.getParameter(\"value\") %>\" /> request.getSession() session"
},
{
"answer_id": 2591347,
"author": "Lino",
"author_id": 310828,
"author_profile": "https://Stackoverflow.com/users/310828",
"pm_score": 2,
"selected": false,
"text": "request.getSession().setAttribute(\"SUBFAMILY\", subFam);\nrequest.getSession().getAttribute(\"SUBFAMILY\");\n"
},
{
"answer_id": 22387021,
"author": "connect2krish",
"author_id": 2914314,
"author_profile": "https://Stackoverflow.com/users/2914314",
"pm_score": 2,
"selected": false,
"text": "request.getSession().setAttribute(\"SUBFAMILY\", subFam);\n SubFamily subFam = (SubFamily)request.getSession().getAttribute(\"SUBFAMILY\");\n"
},
{
"answer_id": 26034057,
"author": "Prasad",
"author_id": 2498468,
"author_profile": "https://Stackoverflow.com/users/2498468",
"pm_score": 2,
"selected": false,
"text": "<form action=\"Enter.do\">\n <button type=\"SUBMIT\" id=\"btnSubmit\" name=\"btnSubmit\">SUBMIT</button>\n</form>\n<% String s=\"opportunity\";\npageContext.setAttribute(\"opp\", s, PageContext.APPLICATION_SCOPE); %>\n String s=(String) request.getServletContext().getAttribute(\"opp\");\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23414/"
] |
229,944
|
<p>I have a search box that doesn't have a submit button, I need to be able to hit enter and then execute a method, how do I do this?</p>
|
[
{
"answer_id": 230345,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 2,
"selected": false,
"text": "this.myTextBox.Attributes.Add(\n \"onkeydown\", \n \"return keyDownHandler(13, 'javascript:\" \n + this.Page.ClientScript.GetPostBackEventReference(this.myButton, string.Empty).Replace(\"'\", \"%27\") \n + \"', event);\");\n function keyDownHandler(iKeyCode, sFunc, e) { \n if (e == null) { \n e = window.event; \n } \n if (e.keyCode == iKeyCode) { \n eval(unescape(sFunc)); return false; \n } \n}\n"
},
{
"answer_id": 230379,
"author": "Max Schilling",
"author_id": 29662,
"author_profile": "https://Stackoverflow.com/users/29662",
"pm_score": 3,
"selected": true,
"text": "<asp:Panel DefaultButton=\"myButton\" runat=\"server\">\n <asp:TextBox ID=\"myTextBox\" runat=\"server\" />\n <asp:Button ID=\"myButton\" runat=\"server\" onclick=\"myButton_Click\" style=\"display: none; \" />\n</asp:Panel>\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29445/"
] |
229,959
|
<p>This question is related to a previous post of mine <a href="https://stackoverflow.com/questions/227225/is-injecting-dao-into-entities-a-bad-thing">Here</a>. Basically, I want to inject a DAO into an entity i.e. </p>
<pre><code>public class User
{
IUserDAO userDAO;
public User()
{
userDAO = IoCContainer.Resolve<IUserDAO>;
}
public User(IUserDAO userDAO)
{
this.userDAO = userDAO;
}
//Wrapped DAO methods i.e
public User Save()
{
return userDAO.Save(this);
}
}
</code></pre>
<p>Here if I had a custom methods in my DAO then I basically have to wrap them in the entity object. So if I had a IUserDAO.Register() I would then have to create a User.Register() method to wrap it. </p>
<p>What would be better is to create a proxy object where the methods from the DAO are dynamically assign to the User object. So I may have something that looks like this:</p>
<pre><code>var User = DAOProxyService.Create(new User());
User.Save();
</code></pre>
<p>This would mean that I can keep the User entity as a pretty dumb class suitable for data transfer over the wire, but also magically give it a bunch of DAO methods.</p>
<p>This is very much out of my confort zone though, and I wondered what I would need to accomplish this? Could I use Castles Dynamic proxy? Also would the C# compiler be able to cope with this and know about the dynamically added methods? </p>
<p>Feel free to let me know if this is nonsense. </p>
<p>EDIT:</p>
<blockquote>
<p>What we need to do it somehow declare DAOProxyService.Create() as returning a User object -- at compile time. This can be done with generics.</p>
</blockquote>
<p>This isnt quite true, what I want to return isn't a User object but a User object with dynamically added UserDAO methods. As this class isn't defnied anywhere the compiler will not know what to make of it. </p>
<p>What I am essentially returning is a new object that looks like: User : IUserDAO, so I guess I could cast as required. But this seems messy. </p>
<p>Looks like what I am looking for is similar to this: <a href="http://www.almostserio.us/articles/2005/01/12/mixins-using-castle-dynamicproxy" rel="nofollow noreferrer">Mixins</a></p>
|
[
{
"answer_id": 230345,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 2,
"selected": false,
"text": "this.myTextBox.Attributes.Add(\n \"onkeydown\", \n \"return keyDownHandler(13, 'javascript:\" \n + this.Page.ClientScript.GetPostBackEventReference(this.myButton, string.Empty).Replace(\"'\", \"%27\") \n + \"', event);\");\n function keyDownHandler(iKeyCode, sFunc, e) { \n if (e == null) { \n e = window.event; \n } \n if (e.keyCode == iKeyCode) { \n eval(unescape(sFunc)); return false; \n } \n}\n"
},
{
"answer_id": 230379,
"author": "Max Schilling",
"author_id": 29662,
"author_profile": "https://Stackoverflow.com/users/29662",
"pm_score": 3,
"selected": true,
"text": "<asp:Panel DefaultButton=\"myButton\" runat=\"server\">\n <asp:TextBox ID=\"myTextBox\" runat=\"server\" />\n <asp:Button ID=\"myButton\" runat=\"server\" onclick=\"myButton_Click\" style=\"display: none; \" />\n</asp:Panel>\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/425/"
] |
229,998
|
<p>I want to copy all of the columns of a row, but not have to specify every column. I am aware of the syntax at <a href="http://dev.mysql.com/doc/refman/5.1/en/insert-select.html" rel="noreferrer">http://dev.mysql.com/doc/refman/5.1/en/insert-select.html</a> but I see no way to ignore a column.</p>
<p>For my example, I am trying to copy all the columns of a row to a new row, except for the primary key.</p>
<p>Is there a way to do that without having to write the query with every field in it?</p>
|
[
{
"answer_id": 230018,
"author": "Eric Lamb",
"author_id": 538,
"author_profile": "https://Stackoverflow.com/users/538",
"pm_score": 1,
"selected": false,
"text": "INSERT INTO `users` (`ID`, `Email`, `UserName`) VALUES\n(1, 'so@so.com', 'StackOverflow')\n INSERT INTO `users` VALUES\n('so@so.com', 'StackOverflow')\n INSERT INTO `users` (`Email`, `UserName`) VALUES\n('so@so.com', 'StackOverflow'),\n('so2@so.com', 'StackOverflow2'),\n('so3@so.com', 'StackOverflow3'),\netc...\n"
},
{
"answer_id": 668060,
"author": "Dipin",
"author_id": 67976,
"author_profile": "https://Stackoverflow.com/users/67976",
"pm_score": 0,
"selected": false,
"text": "auto_increment auto_incremented auto_incremented NO_AUTO_VALUE_ON_ZERO"
},
{
"answer_id": 3918543,
"author": "Lore",
"author_id": 473777,
"author_profile": "https://Stackoverflow.com/users/473777",
"pm_score": 4,
"selected": false,
"text": "id auto_increment CREATE TEMPORARY TABLE temp_table \nAS \nSELECT * FROM source_table WHERE id='7'; \nUPDATE temp_table SET id='100' WHERE id='7';\nINSERT INTO source_table SELECT * FROM temp_table;\nDROP TEMPORARY TABLE temp_table;\n"
},
{
"answer_id": 6309476,
"author": "Casey",
"author_id": 793083,
"author_profile": "https://Stackoverflow.com/users/793083",
"pm_score": 2,
"selected": false,
"text": "$sql = \"SELECT * FROM table_name LIMIT 1\"; \n$res = mysql_query($sql) or die(mysql_error());\nfor ($i = 1; $i < mysql_num_fields($res); $i++) {\n $col_names .= mysql_field_name($res, $i).\", \";\n }\n $col_names = substr($col_names, 0, -2);\n\n$sql = \"INSERT INTO table_name (\".$col_names.\") SELECT \".$col_names.\" FROM table_name WHERE condition \";\n$res = mysql_query($sql) or die(mysql_error());\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/229998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
230,003
|
<p>What is the difference between using a new thread and using a thread from the thread pool? What performance benefits are there and why should I consider using a thread from the pool rather than one I've explicitly created? I'm thinking specifically of .NET here, but general examples are fine.</p>
|
[
{
"answer_id": 230043,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "new Thread().Start()"
},
{
"answer_id": 21001870,
"author": "Marco Guignard",
"author_id": 2087090,
"author_profile": "https://Stackoverflow.com/users/2087090",
"pm_score": 0,
"selected": false,
"text": "positionchanged"
},
{
"answer_id": 35124592,
"author": "PeterM",
"author_id": 635906,
"author_profile": "https://Stackoverflow.com/users/635906",
"pm_score": 3,
"selected": false,
"text": " for (int i = 0; i < ThreadCount; i++) {\n Task.Run(() => { });\n }\n\n for (int i = 0; i < ThreadCount; i++) {\n var t = new Thread(() => { });\n t.Start();\n }\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/986/"
] |
230,006
|
<p>How would I reset the primary key counter on a sql table and update each row with a new primary key?</p>
|
[
{
"answer_id": 230041,
"author": "Codewerks",
"author_id": 17729,
"author_profile": "https://Stackoverflow.com/users/17729",
"pm_score": 2,
"selected": false,
"text": "SELECT Field1, Field2 INTO #MyTable FROM MyTable\n\nTRUNCATE TABLE MyTable\n\nINSERT INTO MyTable\n(Field1, Field2)\nSELECT Field1, Field2 FROM #MyTable\n\nSELECT * FROM MyTable\n-----------------------------------\nID Field1 Field2\n1 Value1 Value2\n"
},
{
"answer_id": 230093,
"author": "Zachary Yates",
"author_id": 8360,
"author_profile": "https://Stackoverflow.com/users/8360",
"pm_score": 3,
"selected": false,
"text": "SET IDENTITY_INSERT [MyTable] ON\n SET IDENTITY_INSERT [MyTable] OFF\n"
},
{
"answer_id": 230346,
"author": "Scott Saad",
"author_id": 4916,
"author_profile": "https://Stackoverflow.com/users/4916",
"pm_score": -1,
"selected": false,
"text": "-- Reset the primary key counter\ndbcc checkident(ErrorCode, reseed, 7000)\n\n-- Move all rows greater than 8000 to the 7000 range\ninsert into ErrorCode\nselect Description from ErrorCode where ErrorCodeID >= 8000\n\n-- Delete the old rows\ndelete ErrorCode where ErrorCodeID >= 8000\n\n-- Reset the primary key counter\ndbcc checkident(ErrorCode, reseed, 8000)\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5618/"
] |
230,014
|
<p>I'm using the ASP.NET 3.5 SP1 System.Web.Routing with classic WebForms, as described in <a href="http://chriscavanagh.wordpress.com/2008/04/25/systemwebrouting-with-webforms-sample/" rel="noreferrer">http://chriscavanagh.wordpress.com/2008/04/25/systemwebrouting-with-webforms-sample/</a></p>
<p><strong>All works fine</strong>, I have custom SEO urls and even the postback works. <strong>But there is a case where the postback always fails</strong> and I get a:</p>
<p><em>Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.</em></p>
<p>Here is the scenario to reproduce the error:</p>
<ol>
<li>Create a standard webform mypage.aspx with a button</li>
<li>Create a Route that maps "a/b/{id}" to "~/mypage.aspx"</li>
<li>When you execute the site, you can navigate <a href="http://localhost:XXXX/a/b/something" rel="noreferrer">http://localhost:XXXX/a/b/something</a> the page works. But when you press the button you get the error. The error doen't happen when the Route is just "a/{id}". </li>
</ol>
<p>It seems to be related to the number of sub-paths in the url. If there are at least 2 sub-paths the viewstate validation fails.</p>
<p>You get the error even with EnableViewStateMac="false".</p>
<p>Any ideas? Is it a bug?</p>
<p>Thanks</p>
|
[
{
"answer_id": 307768,
"author": "JSmyth",
"author_id": 54794,
"author_profile": "https://Stackoverflow.com/users/54794",
"pm_score": 0,
"selected": false,
"text": "<form></form>\n"
},
{
"answer_id": 429911,
"author": "user33090",
"author_id": 33090,
"author_profile": "https://Stackoverflow.com/users/33090",
"pm_score": 1,
"selected": false,
"text": "// TODO: Remove this hack. Without it, the browser appears to always load cached output\nviewContext.HttpContext.Response.Cache.SetExpires(DateTime.Now);\n**ViewUserControlContainerPage containerPage = new ViewUserControlContainerPage(this);**\n// Tracing requires Page IDs to be unique.\nID = Guid.NewGuid().ToString();\ncontainerPage.RenderView(viewContext);\n public ViewUserControlContainerPage(ViewUserControl userControl) {\n Controls.Add(userControl);\n}\n"
},
{
"answer_id": 557611,
"author": "Mauricio Scheffer",
"author_id": 21239,
"author_profile": "https://Stackoverflow.com/users/21239",
"pm_score": 3,
"selected": false,
"text": "ViewUserControl<T> public class ViewUserControlWithoutViewState<T> : ViewUserControl<T> where T : class {\n protected override void LoadViewState(object savedState) {}\n\n protected override object SaveControlState() {\n return null;\n }\n\n protected override void LoadControlState(object savedState) {}\n\n protected override object SaveViewState() {\n return null;\n }\n\n /// <summary>\n /// extracted from System.Web.Mvc.ViewUserControl\n /// </summary>\n /// <param name=\"viewContext\"></param>\n public override void RenderView(ViewContext viewContext) {\n viewContext.HttpContext.Response.Cache.SetExpires(DateTime.Now);\n var containerPage = new ViewUserControlContainerPage(this);\n ID = Guid.NewGuid().ToString();\n RenderViewAndRestoreContentType(containerPage, viewContext);\n }\n\n /// <summary>\n /// extracted from System.Web.Mvc.ViewUserControl\n /// </summary>\n /// <param name=\"containerPage\"></param>\n /// <param name=\"viewContext\"></param>\n public static void RenderViewAndRestoreContentType(ViewPage containerPage, ViewContext viewContext) {\n string contentType = viewContext.HttpContext.Response.ContentType;\n containerPage.RenderView(viewContext);\n viewContext.HttpContext.Response.ContentType = contentType;\n }\n\n /// <summary>\n /// Extracted from System.Web.Mvc.ViewUserControl+ViewUserControlContainerPage\n /// </summary>\n private sealed class ViewUserControlContainerPage : ViewPage {\n // Methods\n public ViewUserControlContainerPage(ViewUserControl userControl) {\n Controls.Add(userControl);\n EnableViewState = false;\n }\n\n protected override object LoadPageStateFromPersistenceMedium() {\n return null;\n }\n\n protected override void SavePageStateToPersistenceMedium(object state) {}\n }\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
230,025
|
<p>I got this error
Response object error 'ASP 0156 : 80004005' </p>
<p>Header Error </p>
<p>/ordermgmt/updateorderstatus.asp, line 1390 </p>
<p>The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content. </p>
<p>I put Response.Buffer=true;
Stilll it is showing error.</p>
<p>I have put reponse,Redirect @ this line number and that will be executed a number of times (it is in a loop).,After the first iteration it is showing this error</p>
|
[
{
"answer_id": 23285687,
"author": "kansal",
"author_id": 3571723,
"author_profile": "https://Stackoverflow.com/users/3571723",
"pm_score": 0,
"selected": false,
"text": "<% Response.Buffer = True %>"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29982/"
] |
230,035
|
<p>Is there a way to display the headerText of the Grid View vertically?</p>
<p><a href="http://img371.imageshack.us/img371/4813/testyk6.jpg" rel="nofollow noreferrer">http://img371.imageshack.us/img371/4813/testyk6.jpg</a></p>
<p>I hope the above link works</p>
<p>Thanks</p>
|
[
{
"answer_id": 230148,
"author": "Travis Collins",
"author_id": 30460,
"author_profile": "https://Stackoverflow.com/users/30460",
"pm_score": 1,
"selected": false,
"text": "<div style=\"width:100%; filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);\">\n This text is rotated 90 degrees.\n</div>\n"
},
{
"answer_id": 391309,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 1,
"selected": false,
"text": "writing-mode: tb-rl;\nfilter: flipv fliph;\n filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);\n -webkit-transform: rotate(270deg);\n -moz-transform: rotate(270deg);\n"
},
{
"answer_id": 10754848,
"author": "annie",
"author_id": 1417441,
"author_profile": "https://Stackoverflow.com/users/1417441",
"pm_score": 0,
"selected": false,
"text": "/*Do this in a loop for each header cell so Cells[0] to cells[however many] and however long the string is so use length properties to get the actual length of the text string */ \n\nprotected void GridView1_SelectedIndexChanged(object sender, EventArgs e)\n {\n StringBuilder vtxt = new StringBuilder();\n vtxt.Append(GridView1.HeaderRow.Cells[0].Text.ToString().Substring(0,1));\n vtxt.Append(\"<br />\");\n vtxt.Append(GridView1.HeaderRow.Cells[0].Text.ToString().Substring(1, 1));\n vtxt.Append(\"<br />\");\n vtxt.Append(GridView1.HeaderRow.Cells[0].Text.ToString().Substring(2, 1));\n vtxt.Append(\"<br />\");\n vtxt.Append(GridView1.HeaderRow.Cells[0].Text.ToString().Substring(3, 1));\n vtxt.Append(\"<br />\");\n vtxt.Append(GridView1.HeaderRow.Cells[0].Text.ToString().Substring(4, 1));\n vtxt.Append(\"<br />\");\n vtxt.Append(GridView1.HeaderRow.Cells[0].Text.ToString().Substring(5, 1));\n vtxt.Append(\"<br />\");\n vtxt.Append(GridView1.HeaderRow.Cells[0].Text.ToString().Substring(6, 1));\n vtxt.Append(\"<br />\");\n vtxt.Append(GridView1.HeaderRow.Cells[0].Text.ToString().Substring(7, 1));\n\n GridView1.HeaderRow.Cells[2].Text = vtxt.ToString();\n }\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21968/"
] |
230,037
|
<p>I am trying to figure out the best way to use Ant to precompile JSPs that will be deployed to an Oracle application server. Even though I am deploying to an Oracle app server I would like to avoid using Oracle's version of Ant.</p>
|
[
{
"answer_id": 235744,
"author": "Brian",
"author_id": 700,
"author_profile": "https://Stackoverflow.com/users/700",
"pm_score": 3,
"selected": false,
"text": "<servlet>\n <servlet-name>jsp</servlet-name>\n <servlet-class>oracle.jsp.runtimev2.JspServlet</servlet-class>\n <init-param>\n <param-name>main_mode</param-name>\n <param-value>justrun</param-value>\n </init-param>\n</servlet>\n <oracle:compileJsp file=\"dist/war/before-${app}war\"\n verbose=\"false\"\n output=\"dist/war/${app}.war\" />\n <project name=\"your-name\" default=\"compile\" basedir=\".\" xmlns:oracle=\"antlib:oracle\">\n...\n</project>\n <!-- Now Precompile the War File (see entry in <project> tag ) -->\n <java jar=\"${env.ORACLE_HOME}/j2ee/home/ojspc.jar\" classpathref=\"jspPreCompileClassPath\" fork=\"true\">\n <arg value=\"-addClasspath\"/>\n <arg pathref=\"classpath\"/>\n <arg line=\"'${dist}/war/a-war-file.war'\"/>\n </java>\n <path id=\"jspPreCompileClassPath\">\n <path location=\"${env.ORACLE_HOME}/j2ee/home/lib/pcl.jar\"/>\n <path location=\"${env.ORACLE_HOME}/j2ee/home/lib/ojsp.jar\"/>\n <path location=\"${env.ORACLE_HOME}/j2ee/home/lib/oc4j-internal.jar\"/>\n <path location=\"${env.ORACLE_HOME}/j2ee/home/lib/servlet.jar\"/>\n <path location=\"${env.ORACLE_HOME}/j2ee/home/lib/commons-el.jar\"/>\n <path location=\"${env.ORACLE_HOME}/j2ee/home/lib/bcel.jar\"/>\n <path location=\"${env.ORACLE_HOME}/lib/xmlparserv2.jar\"/>\n <path location=\"${env.ORACLE_HOME}/j2ee/home/lib/oc4j-schemas.jar\"/>\n <path location=\"${env.ORACLE_HOME}/j2ee/home/jsp/lib/taglib/ojsputil.jar\"/>\n </path>\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230037",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25502/"
] |
230,044
|
<p><strong>Is there some way to force some files to not be merged automatically (force me to manage the merge) when merging a branch back into the main tree?</strong> </p>
<p>For example, I have web.config files that have specific paths based on whether I'm in the Dev or Production system. So, when I need to merge my dev branch back into main, I don't want to modify some of the tags, but other information might need to be updated.</p>
<p>The problem is that the merge may automatically update the settings that need to remain the same. I can easily revert back to the original, but then any new settings would be lost. It seems to be the easiest way to handle this would be for me to manually merge the changes in this case. </p>
<p>It's possible I'm coming at this from the wrong direction since I'm new to Tortoise and SVN.</p>
<p>In addition to the config example that has some good answers below. <strong>Is there a way to force all files to be handled manually during a merge?</strong> It seems like there should be a flag that could be applied to the files to simply make it look like there is a conflict to the flagged file and to handle the merge accordingly.</p>
|
[
{
"answer_id": 230173,
"author": "Adam",
"author_id": 13320,
"author_profile": "https://Stackoverflow.com/users/13320",
"pm_score": 0,
"selected": false,
"text": "if (production) {\n db = prod\n} else {\n db = dev\n}\n /trunk <-- development (or its own branch)\n/branches/\n/branches/production-pre <-- latest stable\n/branches/production-config <-- web.config and related only\n/branches/production-post <-- final merged\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230044",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/288/"
] |
230,062
|
<p>Is there a better way than simply trying to open the file?</p>
<pre><code>int exists(const char *fname)
{
FILE *file;
if ((file = fopen(fname, "r")))
{
fclose(file);
return 1;
}
return 0;
}
</code></pre>
|
[
{
"answer_id": 230067,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 5,
"selected": false,
"text": "stat() stat(2) stat() access() stat()"
},
{
"answer_id": 230068,
"author": "Graeme Perrow",
"author_id": 1821,
"author_profile": "https://Stackoverflow.com/users/1821",
"pm_score": 11,
"selected": true,
"text": "access() unistd.h if (access(fname, F_OK) == 0) {\n // file exists\n} else {\n // file doesn't exist\n}\n unistd.h #ifdef WIN32\n#include <io.h>\n#define F_OK 0\n#define access _access\n#endif\n R_OK W_OK X_OK F_OK R_OK|W_OK W_OK access( fname, W_OK )"
},
{
"answer_id": 230070,
"author": "codebunny",
"author_id": 13667,
"author_profile": "https://Stackoverflow.com/users/13667",
"pm_score": 7,
"selected": false,
"text": "stat #include <sys/stat.h> // stat\n#include <stdbool.h> // bool type\n\nbool file_exists (char *filename) {\n struct stat buffer; \n return (stat (filename, &buffer) == 0);\n}\n #include <stdio.h> // printf\n\nint main(int ac, char **av) {\n if (ac != 2)\n return 1;\n\n if (file_exists(av[1]))\n printf(\"%s exists\\n\", av[1]);\n else\n printf(\"%s does not exist\\n\", av[1]);\n\n return 0;\n}\n"
},
{
"answer_id": 230090,
"author": "SmacL",
"author_id": 22564,
"author_profile": "https://Stackoverflow.com/users/22564",
"pm_score": 3,
"selected": false,
"text": "/* ACCESS.C: This example uses _access to check the\n * file named \"ACCESS.C\" to see if it exists and if\n * writing is allowed.\n */\n\n#include <io.h>\n#include <stdio.h>\n#include <stdlib.h>\n\nvoid main( void )\n{\n /* Check for existence */\n if( (_access( \"ACCESS.C\", 0 )) != -1 )\n {\n printf( \"File ACCESS.C exists\\n\" );\n /* Check for write permission */\n if( (_access( \"ACCESS.C\", 2 )) != -1 )\n printf( \"File ACCESS.C has write permission\\n\" );\n }\n}\n _access(const char *path, int mode ) fopen stat()"
},
{
"answer_id": 230581,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 7,
"selected": false,
"text": "#include <fcntl.h>\n#include <errno.h>\n\nfd = open(pathname, O_CREAT | O_WRONLY | O_EXCL, S_IRUSR | S_IWUSR);\nif (fd < 0) {\n /* failure */\n if (errno == EEXIST) {\n /* the file already existed */\n ...\n }\n} else {\n /* now you can use the file */\n}\n"
},
{
"answer_id": 29510380,
"author": "mesutpiskin",
"author_id": 2647294,
"author_profile": "https://Stackoverflow.com/users/2647294",
"pm_score": 4,
"selected": false,
"text": "FILE *file;\n if((file = fopen(\"sample.txt\",\"r\"))!=NULL)\n {\n // file exists\n fclose(file);\n }\n else\n {\n //File not found, no memory leak since 'file' == NULL\n //fclose(file) would cause an error\n }\n"
},
{
"answer_id": 34184922,
"author": "Michi",
"author_id": 4745612,
"author_profile": "https://Stackoverflow.com/users/4745612",
"pm_score": 3,
"selected": false,
"text": "unistd.h Linux #include <stdio.h>\n#include <stdlib.h>\n#include<unistd.h>\n\nvoid fileCheck(const char *fileName);\n\nint main (void) {\n char *fileName = \"/etc/sudoers\";\n\n fileCheck(fileName);\n return 0;\n}\n\nvoid fileCheck(const char *fileName){\n\n if(!access(fileName, F_OK )){\n printf(\"The File %s\\t was Found\\n\",fileName);\n }else{\n printf(\"The File %s\\t not Found\\n\",fileName);\n }\n\n if(!access(fileName, R_OK )){\n printf(\"The File %s\\t can be read\\n\",fileName);\n }else{\n printf(\"The File %s\\t cannot be read\\n\",fileName);\n }\n\n if(!access( fileName, W_OK )){\n printf(\"The File %s\\t it can be Edited\\n\",fileName);\n }else{\n printf(\"The File %s\\t it cannot be Edited\\n\",fileName);\n }\n\n if(!access( fileName, X_OK )){\n printf(\"The File %s\\t is an Executable\\n\",fileName);\n }else{\n printf(\"The File %s\\t is not an Executable\\n\",fileName);\n }\n}\n The File /etc/sudoers was Found\nThe File /etc/sudoers cannot be read\nThe File /etc/sudoers it cannot be Edited\nThe File /etc/sudoers is not an Executable\n"
},
{
"answer_id": 36492773,
"author": "bharath reddy",
"author_id": 6175665,
"author_profile": "https://Stackoverflow.com/users/6175665",
"pm_score": 3,
"selected": false,
"text": "resolved_file = realpath(file_path, NULL);\nif (!resolved_keyfile) {\n /*File dosn't exists*/\n perror(keyfile);\n return -1;\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1248/"
] |
230,065
|
<p>Are there any good (and preferably free) code coverage tools out there for Perl?</p>
|
[
{
"answer_id": 230149,
"author": "moritz",
"author_id": 14132,
"author_profile": "https://Stackoverflow.com/users/14132",
"pm_score": 6,
"selected": true,
"text": "testcover perl Build.PL\n ./Build testcover\n"
},
{
"answer_id": 236132,
"author": "dland",
"author_id": 18625,
"author_profile": "https://Stackoverflow.com/users/18625",
"pm_score": 3,
"selected": false,
"text": "eval \"use ExtUtils::MakeMaker::Coverage\";\nif( !$@ ) {\n print \"Adding testcover target\\n\";\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27687/"
] |
230,081
|
<p>How do you find out the length/size of the data in an ntext column in SQL? - It's longer than 8000 bytes so I can't cast it to a varchar. Thanks.</p>
|
[
{
"answer_id": 230097,
"author": "korro",
"author_id": 22650,
"author_profile": "https://Stackoverflow.com/users/22650",
"pm_score": 7,
"selected": true,
"text": "SELECT * FROM YourTable WHERE DataLength(NTextFieldName) > 0 \n"
},
{
"answer_id": 232828,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 4,
"selected": false,
"text": "DATALENGTH() LEN() SELECT LEN(CAST('Hello ' AS NVARCHAR(MAX))), \n DATALENGTH(CAST('Hello ' AS NVARCHAR(MAX))), \n DATALENGTH(CAST('Hello ' AS NTEXT))\n DATALENGTH() LEN()"
},
{
"answer_id": 45701317,
"author": "Steve D",
"author_id": 8469204,
"author_profile": "https://Stackoverflow.com/users/8469204",
"pm_score": 1,
"selected": false,
"text": "Select Max(DataLength([NTextFieldName])) from YourTable\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14072/"
] |
230,085
|
<p>We use Grid Control 10.2.0.4, with a catalog repository database also at 10.2.0.4. It seems that after a week or two of being up, the response time of the web interface gets very poor (20+ seconds to navigate to a new page, when normally 2-3 seconds is seen). The only thing we've found to overcome it is a restart of the catalog database and the GC/OMS. No errors reported in the alert log, just unbearable slowness. Are there any Oracle DBA's using GC out there who have seen this (and hopefully found a solution)? </p>
|
[
{
"answer_id": 230097,
"author": "korro",
"author_id": 22650,
"author_profile": "https://Stackoverflow.com/users/22650",
"pm_score": 7,
"selected": true,
"text": "SELECT * FROM YourTable WHERE DataLength(NTextFieldName) > 0 \n"
},
{
"answer_id": 232828,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 4,
"selected": false,
"text": "DATALENGTH() LEN() SELECT LEN(CAST('Hello ' AS NVARCHAR(MAX))), \n DATALENGTH(CAST('Hello ' AS NVARCHAR(MAX))), \n DATALENGTH(CAST('Hello ' AS NTEXT))\n DATALENGTH() LEN()"
},
{
"answer_id": 45701317,
"author": "Steve D",
"author_id": 8469204,
"author_profile": "https://Stackoverflow.com/users/8469204",
"pm_score": 1,
"selected": false,
"text": "Select Max(DataLength([NTextFieldName])) from YourTable\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230085",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8670/"
] |
230,105
|
<p>What's the best data type in SQL to represent Decimal in .NET?</p>
<p>We want to store decimal numbers with up to 9 decimal place precision and want to avoid rounding errors etc on the front end.</p>
<p>Reading about data types, it appears using Decimal in .NET is the best option because you will not get rounding errors, although it is a bit slower than a Double.</p>
<p>We want to carry this through down to the DB and want minimum conversion issues when moving data through the layers. Any suggestions?</p>
|
[
{
"answer_id": 2405477,
"author": "Gareth Farrington",
"author_id": 2021,
"author_profile": "https://Stackoverflow.com/users/2021",
"pm_score": 5,
"selected": false,
"text": "decimal decimal(38, 28)\n decimal(38, 9)\n varchar"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30840/"
] |
230,111
|
<p>I am trying to manipulate a string using Jython, I have included below an example string:</p>
<p>This would be a title for a website :: SiteName<br />
This would be a title for a website :: SiteName :: SiteName</p>
<p>How to remove all instances of ":: Sitename" or ":: SiteName :: SiteName"?</p>
|
[
{
"answer_id": 230240,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 3,
"selected": true,
"text": ">>> str=\"This would be a title for a website :: SiteName\"\n>>> str.replace(\":: SiteName\",\"\")\n'This would be a title for a website '\n>>> str=\"This would be a title for a website :: SiteName :: SiteName\"\n>>> str.replace(\":: SiteName\",\"\")\n'This would be a title for a website '\n"
},
{
"answer_id": 259472,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 0,
"selected": false,
"text": "re import re\n\nsitename = \"sitename\" #NOTE: case-insensitive\nfor s in (\"This would be a title for a website :: SiteName :: SiteName\",\n \"This would be a title for a website :: SiteName\"):\n print(re.sub(r\"(?i)\\s*::\\s*%s\\s*\" % sitename, \"\", s))\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230111",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30786/"
] |
230,126
|
<p>I have a Timestamp value that comes from my application. The user can be in any given local TimeZone.</p>
<p>Since this date is used for a WebService that assumes the time given is always in GMT, I have a need to convert the user's parameter from say (EST) to (GMT). Here's the kicker: The user is oblivious to his TZ. He enters the creation date that he wants to send to the WS, so what I need is:</p>
<p><strong>User enters:</strong> 5/1/2008 6:12 PM (EST) <br>
<strong>The parameter to the WS needs to be</strong>: 5/1/2008 6:12 PM (GMT)</p>
<p>I know TimeStamps are always supposed to be in GMT by default, but when sending the parameter, even though I created my Calendar from the TS (which is supposed to be in GMT), the hours are always off unless the user is in GMT. What am I missing?</p>
<pre><code>Timestamp issuedDate = (Timestamp) getACPValue(inputs_, "issuedDate");
Calendar issueDate = convertTimestampToJavaCalendar(issuedDate);
...
private static java.util.Calendar convertTimestampToJavaCalendar(Timestamp ts_) {
java.util.Calendar cal = java.util.Calendar.getInstance(
GMT_TIMEZONE, EN_US_LOCALE);
cal.setTimeInMillis(ts_.getTime());
return cal;
}
</code></pre>
<p>With the previous Code, this is what I get as a result (Short Format for easy reading):</p>
<p>[May 1, 2008 11:12 PM]</p>
|
[
{
"answer_id": 230313,
"author": "Adam",
"author_id": 30084,
"author_profile": "https://Stackoverflow.com/users/30084",
"pm_score": 2,
"selected": false,
"text": "int offset = TimeZone.getTimeZone(timezoneId).getRawOffset();\n"
},
{
"answer_id": 230320,
"author": "Skip Head",
"author_id": 23271,
"author_profile": "https://Stackoverflow.com/users/23271",
"pm_score": 3,
"selected": false,
"text": "cal.setTimeInMillis(ts_.getTime() - ts_.getTimezoneOffset());\n Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000)\n"
},
{
"answer_id": 230383,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 6,
"selected": false,
"text": "public static Calendar convertToGmt(Calendar cal) {\n\n Date date = cal.getTime();\n TimeZone tz = cal.getTimeZone();\n\n log.debug(\"input calendar has date [\" + date + \"]\");\n\n //Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT \n long msFromEpochGmt = date.getTime();\n\n //gives you the current offset in ms from GMT at the current date\n int offsetFromUTC = tz.getOffset(msFromEpochGmt);\n log.debug(\"offset is \" + offsetFromUTC);\n\n //create a new calendar in GMT timezone, set to this date and add the offset\n Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone(\"GMT\"));\n gmtCal.setTime(date);\n gmtCal.add(Calendar.MILLISECOND, offsetFromUTC);\n\n log.debug(\"Created GMT cal with date [\" + gmtCal.getTime() + \"]\");\n\n return gmtCal;\n}\n Calendar.getInstance() Calendar.getTime() Date"
},
{
"answer_id": 230765,
"author": "Jorge Valois",
"author_id": 30825,
"author_profile": "https://Stackoverflow.com/users/30825",
"pm_score": 6,
"selected": true,
"text": "// Get TimeZone of user\nTimeZone currentTimeZone = sc_.getTimeZone();\nCalendar currentDt = new GregorianCalendar(currentTimeZone, EN_US_LOCALE);\n// Get the Offset from GMT taking DST into account\nint gmtOffset = currentTimeZone.getOffset(\n currentDt.get(Calendar.ERA), \n currentDt.get(Calendar.YEAR), \n currentDt.get(Calendar.MONTH), \n currentDt.get(Calendar.DAY_OF_MONTH), \n currentDt.get(Calendar.DAY_OF_WEEK), \n currentDt.get(Calendar.MILLISECOND));\n// convert to hours\ngmtOffset = gmtOffset / (60*60*1000);\nSystem.out.println(\"Current User's TimeZone: \" + currentTimeZone.getID());\nSystem.out.println(\"Current Offset from GMT (in hrs):\" + gmtOffset);\n// Get TS from User Input\nTimestamp issuedDate = (Timestamp) getACPValue(inputs_, \"issuedDate\");\nSystem.out.println(\"TS from ACP: \" + issuedDate);\n// Set TS into Calendar\nCalendar issueDate = convertTimestampToJavaCalendar(issuedDate);\n// Adjust for GMT (note the offset negation)\nissueDate.add(Calendar.HOUR_OF_DAY, -gmtOffset);\nSystem.out.println(\"Calendar Date converted from TS using GMT and US_EN Locale: \"\n + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)\n .format(issueDate.getTime()));\n"
},
{
"answer_id": 503072,
"author": "Henrik Aasted Sørensen",
"author_id": 13075,
"author_profile": "https://Stackoverflow.com/users/13075",
"pm_score": 4,
"selected": false,
"text": "SimpleDateFormat formatter = new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\");\nformatter.setTimeZone(TimeZone.getTimeZone(\"UTC\"));\n\nCalendar cal = Calendar.getInstance();\nString timestamp = formatter.format(cal.getTime());\n"
},
{
"answer_id": 720813,
"author": "Helpa",
"author_id": 86210,
"author_profile": "https://Stackoverflow.com/users/86210",
"pm_score": 3,
"selected": false,
"text": "/**\n * Adapt calendar to client time zone.\n * @param calendar - adapting calendar\n * @param timeZone - client time zone\n * @return adapt calendar to client time zone\n */\npublic static Calendar convertCalendar(final Calendar calendar, final TimeZone timeZone) {\n Calendar ret = new GregorianCalendar(timeZone);\n ret.setTimeInMillis(calendar.getTimeInMillis() +\n timeZone.getOffset(calendar.getTimeInMillis()) -\n TimeZone.getDefault().getOffset(calendar.getTimeInMillis()));\n ret.getTime();\n return ret;\n}\n"
},
{
"answer_id": 8628145,
"author": "Vitalii Fedorenko",
"author_id": 288671,
"author_profile": "https://Stackoverflow.com/users/288671",
"pm_score": 4,
"selected": false,
"text": "Date utcDate = new Date(timezoneFrom.convertLocalToUTC(date.getTime(), false));\nDate localDate = new Date(timezoneTo.convertUTCToLocal(utcDate.getTime()));\n LocalDateTime localDateTime = LocalDateTime.parse(\"2007-12-03T10:15:30\");\nZonedDateTime fromDateTime = localDateTime.atZone(\n ZoneId.of(\"America/Toronto\"));\nZonedDateTime toDateTime = fromDateTime.withZoneSameInstant(\n ZoneId.of(\"Canada/Newfoundland\"));\n"
},
{
"answer_id": 48456783,
"author": "Basil Bourque",
"author_id": 642706,
"author_profile": "https://Stackoverflow.com/users/642706",
"pm_score": 2,
"selected": false,
"text": "java.sql.Timestamp Instant Instant Instant instant = myResultSet.getObject( … , Instant.class ) ; \n Timestamp Instant instant = myTimestamp.toInstant() ;\n ZoneId continent/region America/Montreal Africa/Casablanca Pacific/Auckland EST IST ZoneId z = ZoneId.of( \"America/Montreal\" ) ;\n Instant ZonedDateTime ZonedDateTime zdt = instant.atZone( z ) ;\n DateTimeFormatter LocalDate ld = LocalDate.parse( dateInput , DateTimeFormatter.ofPattern( \"M/d/uuuu\" , Locale.US ) ) ;\nLocalTime lt = LocalTime.parse( timeInput , DateTimeFormatter.ofPattern( \"H:m a\" , Locale.US ) ) ;\n OffsetDateTime ZoneOffset.UTC OffsetDateTime odt = OffsetDateTime.of( ld , lt , ZoneOffset.UTC ) ;\n ZoneId ZonedDateTime zdt = ZonedDateTime.of( ld , lt , z ) ;\n Instant Instant instant = odt.toInstant() ;\n Instant instant = zdt.toInstant() ; \n myPreparedStatement.setObject( … , instant ) ;\n java.util.Date Calendar SimpleDateFormat Interval YearWeek YearQuarter"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230126",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30825/"
] |
230,128
|
<p>What is the best way to copy the contents of one stream to another? Is there a standard utility method for this?</p>
|
[
{
"answer_id": 230141,
"author": "Nick",
"author_id": 1490,
"author_profile": "https://Stackoverflow.com/users/1490",
"pm_score": 11,
"selected": true,
"text": "Stream.CopyToAsync input.CopyToAsync(output);\n Task await input.CopyToAsync(output)\n\n// Code from here on will be run in a continuation.\n CopyToAsync SynchronizationContext await Stream.CopyTo input.CopyTo(output);\n public static void CopyStream(Stream input, Stream output)\n{\n byte[] buffer = new byte[32768];\n int read;\n while ((read = input.Read(buffer, 0, buffer.Length)) > 0)\n {\n output.Write (buffer, 0, read);\n }\n}\n input.Length"
},
{
"answer_id": 230175,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 0,
"selected": false,
"text": "Stream s1, s2;\nbyte[] buffer = new byte[4096];\nint bytesRead = 0;\nwhile (bytesRead = s1.Read(buffer, 0, buffer.Length) > 0) s2.Write(buffer, 0, bytesRead);\ns1.Close(); s2.Close();\n"
},
{
"answer_id": 671270,
"author": "Kronass",
"author_id": 81106,
"author_profile": "https://Stackoverflow.com/users/81106",
"pm_score": 0,
"selected": false,
"text": "public static void CopyStream(Stream input, Stream output)\n{\n byte[] buffer = new byte[32768];\n long TempPos = input.Position;\n while (true) \n {\n int read = input.Read (buffer, 0, buffer.Length);\n if (read <= 0)\n return;\n output.Write (buffer, 0, read);\n }\n input.Position = TempPos;// or you make Position = 0 to set it at the start\n}\n Stream output = new MemoryStream();\nbyte[] buffer = new byte[32768]; // or you specify the size you want of your buffer\nlong TempPos = input.Position;\nwhile (true) \n{\n int read = input.Read (buffer, 0, buffer.Length);\n if (read <= 0)\n return;\n output.Write (buffer, 0, read);\n }\n input.Position = TempPos;// or you make Position = 0 to set it at the start\n"
},
{
"answer_id": 1253015,
"author": "hannasm",
"author_id": 68042,
"author_profile": "https://Stackoverflow.com/users/68042",
"pm_score": 2,
"selected": false,
"text": "public static void CopySmallTextStream(Stream input, Stream output)\n{\n using (StreamReader reader = new StreamReader(input))\n using (StreamWriter writer = new StreamWriter(output))\n {\n writer.Write(reader.ReadToEnd());\n }\n}\n"
},
{
"answer_id": 1253049,
"author": "Eloff",
"author_id": 152580,
"author_profile": "https://Stackoverflow.com/users/152580",
"pm_score": 5,
"selected": false,
"text": " public static void CopyTo(this Stream src, Stream dest)\n {\n int size = (src.CanSeek) ? Math.Min((int)(src.Length - src.Position), 0x2000) : 0x2000;\n byte[] buffer = new byte[size];\n int n;\n do\n {\n n = src.Read(buffer, 0, buffer.Length);\n dest.Write(buffer, 0, n);\n } while (n != 0); \n }\n\n public static void CopyTo(this MemoryStream src, Stream dest)\n {\n dest.Write(src.GetBuffer(), (int)src.Position, (int)(src.Length - src.Position));\n }\n\n public static void CopyTo(this Stream src, MemoryStream dest)\n {\n if (src.CanSeek)\n {\n int pos = (int)dest.Position;\n int length = (int)(src.Length - src.Position) + pos;\n dest.SetLength(length); \n\n while(pos < length) \n pos += src.Read(dest.GetBuffer(), pos, length - pos);\n }\n else\n src.CopyTo((Stream)dest);\n }\n"
},
{
"answer_id": 3089903,
"author": "Joshua",
"author_id": 368954,
"author_profile": "https://Stackoverflow.com/users/368954",
"pm_score": 6,
"selected": false,
"text": "MemoryStream .WriteTo(outstream); .CopyTo instream.CopyTo(outstream);\n"
},
{
"answer_id": 8042598,
"author": "mdonatas",
"author_id": 79981,
"author_profile": "https://Stackoverflow.com/users/79981",
"pm_score": 0,
"selected": false,
"text": "const int BUFFER_SIZE = 4096;\n\nstatic byte[] bufferForRead = new byte[BUFFER_SIZE];\nstatic byte[] bufferForWrite = new byte[BUFFER_SIZE];\n\nstatic Stream sourceStream = new MemoryStream();\nstatic Stream destinationStream = new MemoryStream();\n\nstatic void Main(string[] args)\n{\n // Initial read from source stream\n sourceStream.BeginRead(bufferForRead, 0, BUFFER_SIZE, BeginReadCallback, null);\n}\n\nprivate static void BeginReadCallback(IAsyncResult asyncRes)\n{\n // Finish reading from source stream\n int bytesRead = sourceStream.EndRead(asyncRes);\n // Make a copy of the buffer as we'll start another read immediately\n Array.Copy(bufferForRead, 0, bufferForWrite, 0, bytesRead);\n // Write copied buffer to destination stream\n destinationStream.BeginWrite(bufferForWrite, 0, bytesRead, BeginWriteCallback, null);\n // Start the next read (looks like async recursion I guess)\n sourceStream.BeginRead(bufferForRead, 0, BUFFER_SIZE, BeginReadCallback, null);\n}\n\nprivate static void BeginWriteCallback(IAsyncResult asyncRes)\n{\n // Finish writing to destination stream\n destinationStream.EndWrite(asyncRes);\n}\n"
},
{
"answer_id": 11684353,
"author": "Jayesh Sorathia",
"author_id": 1282729,
"author_profile": "https://Stackoverflow.com/users/1282729",
"pm_score": 2,
"selected": false,
"text": " FileStream objFileStream = File.Open(Server.MapPath(\"TextFile.txt\"), FileMode.Open);\n Response.Write(string.Format(\"FileStream Content length: {0}\", objFileStream.Length.ToString()));\n\n MemoryStream objMemoryStream = new MemoryStream();\n\n // Copy File Stream to Memory Stream using CopyTo method\n objFileStream.CopyTo(objMemoryStream);\n Response.Write(\"<br/><br/>\");\n Response.Write(string.Format(\"MemoryStream Content length: {0}\", objMemoryStream.Length.ToString()));\n Response.Write(\"<br/><br/>\");\n"
},
{
"answer_id": 17382532,
"author": "ntiago",
"author_id": 2534996,
"author_profile": "https://Stackoverflow.com/users/2534996",
"pm_score": 0,
"selected": false,
"text": "MemoryStream1.WriteTo(MemoryStream2);\n"
},
{
"answer_id": 50100908,
"author": "Graham Laight",
"author_id": 1649135,
"author_profile": "https://Stackoverflow.com/users/1649135",
"pm_score": 0,
"selected": false,
"text": " MemoryStream source = new MemoryStream(byteArray);\n MemoryStream copy = new MemoryStream(byteArray);\n"
},
{
"answer_id": 63276155,
"author": "HasH",
"author_id": 1817702,
"author_profile": "https://Stackoverflow.com/users/1817702",
"pm_score": -1,
"selected": false,
"text": "Stream stream = new MemoryStream();\n MemoryStream newMs = (MemoryStream)stream;\n\nbyte[] getByte = newMs.ToArray();\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/341413/"
] |
230,138
|
<p>I have a table that was imported as all UPPER CASE and I would like to turn it into Proper Case. What script have any of you used to complete this?</p>
|
[
{
"answer_id": 230177,
"author": "Galwegian",
"author_id": 3201,
"author_profile": "https://Stackoverflow.com/users/3201",
"pm_score": 8,
"selected": true,
"text": "create function ProperCase(@Text as varchar(8000))\nreturns varchar(8000)\nas\nbegin\n declare @Reset bit;\n declare @Ret varchar(8000);\n declare @i int;\n declare @c char(1);\n\n if @Text is null\n return null;\n\n select @Reset = 1, @i = 1, @Ret = '';\n\n while (@i <= len(@Text))\n select @c = substring(@Text, @i, 1),\n @Ret = @Ret + case when @Reset = 1 then UPPER(@c) else LOWER(@c) end,\n @Reset = case when @c like '[a-zA-Z]' then 0 else 1 end,\n @i = @i + 1\n return @Ret\nend\n"
},
{
"answer_id": 230224,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 7,
"selected": false,
"text": "CREATE FUNCTION ToProperCase(@string VARCHAR(255)) RETURNS VARCHAR(255)\nAS\nBEGIN\n DECLARE @i INT -- index\n DECLARE @l INT -- input length\n DECLARE @c NCHAR(1) -- current char\n DECLARE @f INT -- first letter flag (1/0)\n DECLARE @o VARCHAR(255) -- output string\n DECLARE @w VARCHAR(10) -- characters considered as white space\n\n SET @w = '[' + CHAR(13) + CHAR(10) + CHAR(9) + CHAR(160) + ' ' + ']'\n SET @i = 1\n SET @l = LEN(@string)\n SET @f = 1\n SET @o = ''\n\n WHILE @i <= @l\n BEGIN\n SET @c = SUBSTRING(@string, @i, 1)\n IF @f = 1 \n BEGIN\n SET @o = @o + @c\n SET @f = 0\n END\n ELSE\n BEGIN\n SET @o = @o + LOWER(@c)\n END\n\n IF @c LIKE @w SET @f = 1\n\n SET @i = @i + 1\n END\n\n RETURN @o\nEND\n dbo.ToProperCase('ALL UPPER CASE and SOME lower ÄÄ ÖÖ ÜÜ ÉÉ ØØ ĈĈ ÆÆ')\n-----------------------------------------------------------------\nAll Upper Case and Some lower Ää Öö Üü Éé Øø Cc Ææ\n"
},
{
"answer_id": 230290,
"author": "Cervo",
"author_id": 16219,
"author_profile": "https://Stackoverflow.com/users/16219",
"pm_score": 0,
"selected": false,
"text": "IF OBJECT_ID('dbo.ProperCase') IS NOT NULL\n DROP FUNCTION dbo.ProperCase\nGO\nCREATE FUNCTION dbo.PROPERCASE (\n @str VARCHAR(8000))\nRETURNS VARCHAR(8000)\nAS\nBEGIN\n SET @str = ' ' + @str\n SET @str = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @str, ' a', ' A'), ' b', ' B'), ' c', ' C'), ' d', ' D'), ' e', ' E'), ' f', ' F'), ' g', ' G'), ' h', ' H'), ' i', ' I'), ' j', ' J'), ' k', ' K'), ' l', ' L'), ' m', ' M'), ' n', ' N'), ' o', ' O'), ' p', ' P'), ' q', ' Q'), ' r', ' R'), ' s', ' S'), ' t', ' T'), ' u', ' U'), ' v', ' V'), ' w', ' W'), ' x', ' X'), ' y', ' Y'), ' z', ' Z')\n RETURN RIGHT(@str, LEN(@str) - 1)\nEND\nGO\n -- Code Generator for expression\nDECLARE @x INT,\n @c CHAR(1),\n @sql VARCHAR(8000)\nSET @x = 0\nSET @sql = '@str' -- actual variable/column you want to replace\nWHILE @x < 26\nBEGIN\n SET @c = CHAR(ASCII('a') + @x)\n SET @sql = 'REPLACE(' + @sql + ', '' ' + @c+ ''', '' ' + UPPER(@c) + ''')'\n SET @x = @x + 1\nEND\nPRINT @sql\n -- Code Generator for expression\nDECLARE @x INT,\n @c CHAR(1),\n @sql VARCHAR(8000),\n @count INT\nSEt @x = 0\nSET @count = 0\nSET @sql = '@str' -- actual variable you want to replace\nWHILE @x < 256\nBEGIN\n SET @c = CHAR(@x)\n -- Only generate replacement expression for characters where upper and lowercase differ\n IF @x = ASCII(LOWER(@c)) AND @x != ASCII(UPPER(@c))\n BEGIN\n SET @sql = 'REPLACE(' + @sql + ', '' ' + @c+ ''', '' ' + UPPER(@c) + ''')'\n SET @count = @count + 1\n END\n SET @x = @x + 1\nEND\nPRINT @sql\nPRINT 'Total characters substituted: ' + CONVERT(VARCHAR(255), @count)\n IF OBJECT_ID('dbo.ProperCase') IS NOT NULL\n DROP FUNCTION dbo.ProperCase\nGO\nCREATE FUNCTION dbo.PROPERCASE (\n @str VARCHAR(8000))\nRETURNS VARCHAR(8000)\nAS\nBEGIN\n SET @str = ' ' + @str\nSET @str = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@str, ' a', ' A'), ' b', ' B'), ' c', ' C'), ' d', ' D'), ' e', ' E'), ' f', ' F'), ' g', ' G'), ' h', ' H'), ' i', ' I'), ' j', ' J'), ' k', ' K'), ' l', ' L'), ' m', ' M'), ' n', ' N'), ' o', ' O'), ' p', ' P'), ' q', ' Q'), ' r', ' R'), ' s', ' S'), ' t', ' T'), ' u', ' U'), ' v', ' V'), ' w', ' W'), ' x', ' X'), ' y', ' Y'), ' z', ' Z'), ' š', ' Š'), ' œ', ' Œ'), ' ž', ' Ž'), ' à', ' À'), ' á', ' Á'), ' â', ' Â'), ' ã', ' Ã'), ' ä', ' Ä'), ' å', ' Å'), ' æ', ' Æ'), ' ç', ' Ç'), ' è', ' È'), ' é', ' É'), ' ê', ' Ê'), ' ë', ' Ë'), ' ì', ' Ì'), ' í', ' Í'), ' î', ' Î'), ' ï', ' Ï'), ' ð', ' Ð'), ' ñ', ' Ñ'), ' ò', ' Ò'), ' ó', ' Ó'), ' ô', ' Ô'), ' õ', ' Õ'), ' ö', ' Ö'), ' ø', ' Ø'), ' ù', ' Ù'), ' ú', ' Ú'), ' û', ' Û'), ' ü', ' Ü'), ' ý', ' Ý'), ' þ', ' Þ'), ' ÿ', ' Ÿ')\n RETURN RIGHT(@str, LEN(@str) - 1)\nEND\nGO\n"
},
{
"answer_id": 231705,
"author": "nathan_jr",
"author_id": 3769,
"author_profile": "https://Stackoverflow.com/users/3769",
"pm_score": 1,
"selected": false,
"text": "declare @str nvarchar(8000)\ndeclare @alpha table (low nchar(1), up nchar(1))\n\n\nset @str = 'ALL UPPER CASE and SOME lower ÄÄ ÖÖ ÜÜ ÉÉ ØØ ĈĈ ÆÆ'\n\n-- stage the alpha (needs number table)\ninsert into @alpha\n -- A-Z / a-z\n select nchar(n+32),\n nchar(n)\n from dbo.Number\n where n between 65 and 90 or\n n between 192 and 223\n\n-- append space at start of str\nset @str = lower(' ' + @str)\n\n-- upper all lower case chars preceded by space\nselect @str = replace(@str, ' ' + low, ' ' + up) \nfrom @Alpha\n\nselect @str\n"
},
{
"answer_id": 1007802,
"author": "Merritt",
"author_id": 60385,
"author_profile": "https://Stackoverflow.com/users/60385",
"pm_score": 0,
"selected": false,
"text": "create FUNCTION PROPERCASE\n(\n--The string to be converted to proper case\n@input varchar(8000)\n)\n--This function returns the proper case string of varchar type\nRETURNS varchar(8000)\nAS\nBEGIN\nIF @input IS NULL\nBEGIN\n--Just return NULL if input string is NULL\nRETURN NULL\nEND\n\n--Character variable declarations\nDECLARE @output varchar(8000)\n--Integer variable declarations\nDECLARE @ctr int, @len int, @found_at int\n--Constant declarations\nDECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int\n\n--Variable/Constant initializations\nSET @ctr = 1\nSET @len = LEN(@input)\nSET @output = ''\nSET @LOWER_CASE_a = 97\nSET @LOWER_CASE_z = 122\nSET @Delimiter = ' ,-'\nSET @UPPER_CASE_A = 65\nSET @UPPER_CASE_Z = 90\n\nWHILE @ctr <= @len\nBEGIN\n--This loop will take care of reccuring white spaces\nWHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) > 0\nBEGIN\nSET @output = @output + SUBSTRING(@input,@ctr,1)\nSET @ctr = @ctr + 1\nEND\n\nIF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a AND @LOWER_CASE_z\nBEGIN\n--Converting the first character to upper case\nSET @output = @output + UPPER(SUBSTRING(@input,@ctr,1))\nEND\nELSE\nBEGIN\nSET @output = @output + SUBSTRING(@input,@ctr,1)\nEND\n\nSET @ctr = @ctr + 1\n\nWHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 AND (@ctr <= @len)\nBEGIN\nIF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A AND @UPPER_CASE_Z\nBEGIN\nSET @output = @output + LOWER(SUBSTRING(@input,@ctr,1))\nEND\nELSE\nBEGIN\nSET @output = @output + SUBSTRING(@input,@ctr,1)\nEND\nSET @ctr = @ctr + 1\nEND\n\nEND\nRETURN @output\nEND\n\n\n\nGO\nSET QUOTED_IDENTIFIER OFF\nGO\nSET ANSI_NULLS ON\nGO\n"
},
{
"answer_id": 1764042,
"author": "Dennis Allen",
"author_id": 214691,
"author_profile": "https://Stackoverflow.com/users/214691",
"pm_score": 2,
"selected": false,
"text": "'[^a-z]' '[' + Char(32) + Char(9) + Char(13) + Char(10) + ']' CREATE FUNCTION String.InitCap( @string nvarchar(4000) ) RETURNS nvarchar(4000) AS\nBEGIN\n\n-- 1. Convert all letters to lower case\n DECLARE @InitCap nvarchar(4000); SET @InitCap = Lower(@string);\n\n-- 2. Using a Sequence, replace the letters that should be upper case with their upper case version\n SELECT @InitCap = Stuff( @InitCap, n, 1, Upper( SubString( @InitCap, n, 1 ) ) )\n FROM (\n SELECT (1 + n1.n + n10.n + n100.n + n1000.n) AS n\n FROM (SELECT 0 AS n UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) AS n1\n CROSS JOIN (SELECT 0 AS n UNION SELECT 10 UNION SELECT 20 UNION SELECT 30 UNION SELECT 40 UNION SELECT 50 UNION SELECT 60 UNION SELECT 70 UNION SELECT 80 UNION SELECT 90) AS n10\n CROSS JOIN (SELECT 0 AS n UNION SELECT 100 UNION SELECT 200 UNION SELECT 300 UNION SELECT 400 UNION SELECT 500 UNION SELECT 600 UNION SELECT 700 UNION SELECT 800 UNION SELECT 900) AS n100\n CROSS JOIN (SELECT 0 AS n UNION SELECT 1000 UNION SELECT 2000 UNION SELECT 3000) AS n1000\n ) AS Sequence\n WHERE \n n BETWEEN 1 AND Len( @InitCap )\n AND SubString( @InitCap, n, 1 ) LIKE '[a-z]' /* this character is a letter */\n AND (\n n = 1 /* this character is the first `character` */\n OR SubString( @InitCap, n-1, 1 ) LIKE '[^a-z]' /* the previous character is NOT a letter */\n )\n AND (\n n < 3 /* only test the 3rd or greater characters for this exception */\n OR SubString( @InitCap, n-2, 3 ) NOT LIKE '[a-z]''[a-z]' /* exception: The pattern <letter>'<letter> should not capatolize the letter following the apostrophy */\n )\n\n-- 3. Return the modified version of the input\n RETURN @InitCap\n\nEND\n"
},
{
"answer_id": 20660732,
"author": "Richard Sayakanit",
"author_id": 302589,
"author_profile": "https://Stackoverflow.com/users/302589",
"pm_score": 6,
"selected": false,
"text": "UPDATE titles\n SET title =\n UPPER(LEFT(title, 1)) +\n LOWER(RIGHT(title, LEN(title) - 1))\n"
},
{
"answer_id": 28712621,
"author": "Harmeet Singh Bhamra",
"author_id": 2758965,
"author_profile": "https://Stackoverflow.com/users/2758965",
"pm_score": 4,
"selected": false,
"text": "CREATE FUNCTION [dbo].[fnConvert_TitleCase] (@InputString VARCHAR(4000) )\nRETURNS VARCHAR(4000)\nAS\nBEGIN\nDECLARE @Index INT\nDECLARE @Char CHAR(1)\nDECLARE @OutputString VARCHAR(255)\n\nSET @OutputString = LOWER(@InputString)\nSET @Index = 2\nSET @OutputString = STUFF(@OutputString, 1, 1,UPPER(SUBSTRING(@InputString,1,1)))\n\nWHILE @Index <= LEN(@InputString)\nBEGIN\n SET @Char = SUBSTRING(@InputString, @Index, 1)\n IF @Char IN (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&','''','(')\n IF @Index + 1 <= LEN(@InputString)\nBEGIN\n IF @Char != ''''\n OR\n UPPER(SUBSTRING(@InputString, @Index + 1, 1)) != 'S'\n SET @OutputString =\n STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))\nEND\n SET @Index = @Index + 1\nEND\n\nRETURN ISNULL(@OutputString,'')\nEND\n select dbo.fnConvert_TitleCase(Upper('ÄÄ ÖÖ ÜÜ ÉÉ ØØ ĈĈ ÆÆ')) as test\nselect dbo.fnConvert_TitleCase(upper('Whatever the mind of man can conceive and believe, it can achieve. – Napoleon hill')) as test\n"
},
{
"answer_id": 31191399,
"author": "Kenjamarticus",
"author_id": 5074978,
"author_profile": "https://Stackoverflow.com/users/5074978",
"pm_score": 2,
"selected": false,
"text": "UPPER(substring(input_column_name,1,1)) + LOWER(substring(input_column_name, 2, len(input_column_name)-1))\n"
},
{
"answer_id": 38646988,
"author": "Alansoft",
"author_id": 3281610,
"author_profile": "https://Stackoverflow.com/users/3281610",
"pm_score": 3,
"selected": false,
"text": "CREATE FUNCTION [dbo].[fnToProperCase]( @name nvarchar(500) )\nRETURNS nvarchar(500)\nAS\nBEGIN\ndeclare @pos int = 1\n , @pos2 int\n\nif (@name <> '')--or @name = lower(@name) collate SQL_Latin1_General_CP1_CS_AS or @name = upper(@name) collate SQL_Latin1_General_CP1_CS_AS)\nbegin\n set @name = lower(rtrim(@name))\n while (1 = 1)\n begin\n set @name = stuff(@name, @pos, 1, upper(substring(@name, @pos, 1)))\n set @pos2 = patindex('%[- ''.)(]%', substring(@name, @pos, 500))\n set @pos += @pos2\n if (isnull(@pos2, 0) = 0 or @pos > len(@name))\n break\n end\nend\n\nreturn @name\nEND\nGO\n"
},
{
"answer_id": 39394049,
"author": "Vorlic",
"author_id": 4248435,
"author_profile": "https://Stackoverflow.com/users/4248435",
"pm_score": -1,
"selected": false,
"text": "SELECT UPPER('Put YoUR O'So oddLy casED McWeird-nAme von rightHERE here')"
},
{
"answer_id": 51403256,
"author": "FriskyKitty",
"author_id": 897184,
"author_profile": "https://Stackoverflow.com/users/897184",
"pm_score": 0,
"selected": false,
"text": "InitCap() SELECT ID\n ,InitCap(LastName ||', '|| FirstName ||' '|| Nvl(MiddleName,'')) AS RecipientName\nFROM SomeTable\n"
},
{
"answer_id": 51498901,
"author": "Sathish Babu",
"author_id": 10127962,
"author_profile": "https://Stackoverflow.com/users/10127962",
"pm_score": 0,
"selected": false,
"text": "Select Jobtitle,\nconcat(Upper(LEFT(jobtitle,1)), SUBSTRING(jobtitle,2,LEN(jobtitle))) as Propercase\nFrom [HumanResources].[Employee]\n"
},
{
"answer_id": 53231234,
"author": "Gabe",
"author_id": 220997,
"author_profile": "https://Stackoverflow.com/users/220997",
"pm_score": 1,
"selected": false,
"text": "STRING_SPLIT STRING_AGG STRING_AGG STUFF/XML SELECT StateName = 'North Carolina' \nINTO #States\nUNION ALL\nSELECT 'Texas'\n\n\n;WITH cteData AS \n(\n SELECT \n UPPER(LEFT(value, 1)) +\n LOWER(RIGHT(value, LEN(value) - 1)) value, op.StateName\n FROM #States op\n CROSS APPLY STRING_SPLIT(op.StateName, ' ') AS ss\n)\nSELECT \n STRING_AGG(value, ' ')\nFROM cteData c \nGROUP BY StateName\n"
},
{
"answer_id": 54932265,
"author": "reggaeguitar",
"author_id": 2125444,
"author_profile": "https://Stackoverflow.com/users/2125444",
"pm_score": 1,
"selected": false,
"text": " update tableName set columnName = \n upper(SUBSTRING(columnName, 1, 1)) + substring(columnName, 2, len(columnName)) from tableName\n"
},
{
"answer_id": 55631111,
"author": "philipnye",
"author_id": 4659442,
"author_profile": "https://Stackoverflow.com/users/4659442",
"pm_score": 2,
"selected": false,
"text": "St Elizabeth's St Elizabeth'S create function properCase(@text as varchar(8000))\nreturns varchar(8000)\nas\nbegin\n declare @reset int;\n declare @ret varchar(8000);\n declare @i int;\n declare @c char(1);\n declare @d char(1);\n\n if @text is null\n return null;\n\n select @reset = 1, @i = 1, @ret = '';\n\n while (@i <= len(@text))\n select\n @c = substring(@text, @i, 1),\n @d = substring(@text, @i+1, 1),\n @ret = @ret + case when @reset = 1 or (@reset=-1 and @c!='s') or (@reset=-1 and @c='s' and @d!=' ') then upper(@c) else lower(@c) end,\n @reset = case when @c like '[a-za-z]' then 0 when @c='''' then -1 else 1 end,\n @i = @i + 1\n return @ret\nend\n st elizabeth's St Elizabeth's o'keefe O'Keefe o'sullivan O'Sullivan"
},
{
"answer_id": 58289601,
"author": "Zexks Marquise",
"author_id": 4205675,
"author_profile": "https://Stackoverflow.com/users/4205675",
"pm_score": 1,
"selected": false,
"text": "CREATE FUNCTION ProperCase(@Text AS NVARCHAR(MAX))\nRETURNS NVARCHAR(MAX)\nAS BEGIN\n\n DECLARE @return NVARCHAR(MAX)\n\n SELECT @return = COALESCE(@return + ' ', '') + Word FROM (\n SELECT CASE\n WHEN LOWER(value) = 'llc' THEN UPPER(value)\n WHEN LOWER(value) = 'lp' THEN UPPER(value) --Add as many new special cases as needed\n ELSE\n CASE WHEN LEN(value) = 1\n THEN UPPER(value)\n ELSE UPPER(LEFT(value, 1)) + (LOWER(RIGHT(value, LEN(value) - 1)))\n END\n END AS Word\n FROM STRING_SPLIT(@Text, ' ')\n ) tmp\n\n RETURN @return\nEND\n"
},
{
"answer_id": 64435946,
"author": "cryocaustik",
"author_id": 3931046,
"author_profile": "https://Stackoverflow.com/users/3931046",
"pm_score": 2,
"selected": false,
"text": "\nwith t as (\n select 'GOOFYEAR Tire and Rubber Company' as n\n union all\n select 'THE HAPPY BEAR' as n\n union all\n select 'MONK HOUSE SALES' as n\n union all\n select 'FORUM COMMUNICATIONS' as n\n)\nselect\n n,\n (\n select ' ' + (\n upper(left(value, 1))\n + lower(substring(value, 2, 999))\n )\n from (\n select value\n from string_split(t.n, ' ')\n ) as sq\n for xml path ('')\n ) as title_cased\nfrom t\n"
},
{
"answer_id": 66825487,
"author": "JoshRoss",
"author_id": 81010,
"author_profile": "https://Stackoverflow.com/users/81010",
"pm_score": 0,
"selected": false,
"text": "CREATE OR ALTER FUNCTION dbo.ProperCase(@value varchar(MAX)) RETURNS varchar(MAX) AS \n BEGIN\n \n RETURN (SELECT STRING_AGG(CASE lv WHEN 0 THEN '' WHEN 1 THEN UPPER(value) \n ELSE UPPER(LEFT(value,1)) + LOWER(RIGHT(value,lv-1)) END,' ') \n FROM STRING_SPLIT(TRIM(@value),' ') AS ss \n CROSS APPLY (SELECT LEN(VALUE) lv) AS reuse \n WHERE @value IS NOT NULL)\n\n END\n"
},
{
"answer_id": 69184214,
"author": "Joe Shakely",
"author_id": 7537658,
"author_profile": "https://Stackoverflow.com/users/7537658",
"pm_score": 0,
"selected": false,
"text": "create function [dbo].Pascal (@string varchar(max))\nreturns varchar(max)\nas\nbegin\n declare @Index int\n ,@ResultString varchar(max)\n\n set @Index = 1\n set @ResultString = ''\n\n while (@Index < LEN(@string) + 1)\n begin\n if (@Index = 1)\n begin\n set @ResultString += UPPER(SUBSTRING(@string, @Index, 1))\n set @Index += 1\n end\n else if (\n (\n SUBSTRING(@string, @Index - 1, 1) = ' '\n or SUBSTRING(@string, @Index - 1, 1) = '-'\n or SUBSTRING(@string, @Index + 1, 1) = '-'\n )\n and @Index + 1 <> LEN(@string) + 1\n )\n begin\n set @ResultString += UPPER(SUBSTRING(@string, @Index, 1))\n set @Index += 1\n end\n else\n begin\n set @ResultString += LOWER(SUBSTRING(@string, @Index, 1))\n set @Index += 1\n end\n end\n\n if (@@ERROR <> 0)\n begin\n set @ResultString = @string\n end\n\n return replace(replace(replace(@ResultString, ' ii', ' II'), ' iii', ' III'), ' iv', ' IV')\nend\n"
},
{
"answer_id": 74368743,
"author": "David Zayn",
"author_id": 8697724,
"author_profile": "https://Stackoverflow.com/users/8697724",
"pm_score": 1,
"selected": false,
"text": "SELECT INITCAP(title) FROM data;\n SELECT dbo.InitCap(title) FROM data;\n -- Drop the function if it already exists\n IF OBJECT_ID('dbo.InitCap') IS NOT NULL\n DROP FUNCTION dbo.InitCap;\n GO\n \n -- Implementing Oracle INITCAP function\n CREATE FUNCTION dbo.InitCap (@inStr VARCHAR(8000))\n RETURNS VARCHAR(8000)\n AS\n BEGIN\n DECLARE @outStr VARCHAR(8000) = LOWER(@inStr),\n @char CHAR(1), \n @alphanum BIT = 0,\n @len INT = LEN(@inStr),\n @pos INT = 1; \n \n -- Iterate through all characters in the input string\n WHILE @pos <= @len BEGIN\n \n -- Get the next character\n SET @char = SUBSTRING(@inStr, @pos, 1);\n \n -- If the position is first, or the previous characater is not alphanumeric\n -- convert the current character to upper case\n IF @pos = 1 OR @alphanum = 0\n SET @outStr = STUFF(@outStr, @pos, 1, UPPER(@char));\n \n SET @pos = @pos + 1;\n \n -- Define if the current character is non-alphanumeric\n IF ASCII(@char) <= 47 OR (ASCII(@char) BETWEEN 58 AND 64) OR\n (ASCII(@char) BETWEEN 91 AND 96) OR (ASCII(@char) BETWEEN 123 AND 126)\n SET @alphanum = 0;\n ELSE\n SET @alphanum = 1;\n \n END\n \n RETURN @outStr; \n END\n GO\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7952/"
] |
230,150
|
<p>Visual Studio 2008 w/Sp1</p>
<p>To reproduce my problem I simply create a new .Net 2.0 web application and add a page with the following markup:</p>
<pre><code><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication5._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:button id="button1" runat="server" />
</div>
</form>
</body>
</html>
</code></pre>
<p>what happens is that a line is drawn under :button with the statement "Validation (): Element 'button' is not supported."</p>
<p>I've tried repairing the .net framework; however, that had no impact. This started happening on two different machines, one is vista the other is XP within the past week.</p>
<p><strong>UPDATE:</strong> I closed this question because after spending 2 days trying to fix it I gave up and performed a complete reinstall of Visual Studio 2008. This resolved whatever was jacked up and now the machines in question work properly. I upvoted each of you for the help.</p>
|
[
{
"answer_id": 230177,
"author": "Galwegian",
"author_id": 3201,
"author_profile": "https://Stackoverflow.com/users/3201",
"pm_score": 8,
"selected": true,
"text": "create function ProperCase(@Text as varchar(8000))\nreturns varchar(8000)\nas\nbegin\n declare @Reset bit;\n declare @Ret varchar(8000);\n declare @i int;\n declare @c char(1);\n\n if @Text is null\n return null;\n\n select @Reset = 1, @i = 1, @Ret = '';\n\n while (@i <= len(@Text))\n select @c = substring(@Text, @i, 1),\n @Ret = @Ret + case when @Reset = 1 then UPPER(@c) else LOWER(@c) end,\n @Reset = case when @c like '[a-zA-Z]' then 0 else 1 end,\n @i = @i + 1\n return @Ret\nend\n"
},
{
"answer_id": 230224,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 7,
"selected": false,
"text": "CREATE FUNCTION ToProperCase(@string VARCHAR(255)) RETURNS VARCHAR(255)\nAS\nBEGIN\n DECLARE @i INT -- index\n DECLARE @l INT -- input length\n DECLARE @c NCHAR(1) -- current char\n DECLARE @f INT -- first letter flag (1/0)\n DECLARE @o VARCHAR(255) -- output string\n DECLARE @w VARCHAR(10) -- characters considered as white space\n\n SET @w = '[' + CHAR(13) + CHAR(10) + CHAR(9) + CHAR(160) + ' ' + ']'\n SET @i = 1\n SET @l = LEN(@string)\n SET @f = 1\n SET @o = ''\n\n WHILE @i <= @l\n BEGIN\n SET @c = SUBSTRING(@string, @i, 1)\n IF @f = 1 \n BEGIN\n SET @o = @o + @c\n SET @f = 0\n END\n ELSE\n BEGIN\n SET @o = @o + LOWER(@c)\n END\n\n IF @c LIKE @w SET @f = 1\n\n SET @i = @i + 1\n END\n\n RETURN @o\nEND\n dbo.ToProperCase('ALL UPPER CASE and SOME lower ÄÄ ÖÖ ÜÜ ÉÉ ØØ ĈĈ ÆÆ')\n-----------------------------------------------------------------\nAll Upper Case and Some lower Ää Öö Üü Éé Øø Cc Ææ\n"
},
{
"answer_id": 230290,
"author": "Cervo",
"author_id": 16219,
"author_profile": "https://Stackoverflow.com/users/16219",
"pm_score": 0,
"selected": false,
"text": "IF OBJECT_ID('dbo.ProperCase') IS NOT NULL\n DROP FUNCTION dbo.ProperCase\nGO\nCREATE FUNCTION dbo.PROPERCASE (\n @str VARCHAR(8000))\nRETURNS VARCHAR(8000)\nAS\nBEGIN\n SET @str = ' ' + @str\n SET @str = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @str, ' a', ' A'), ' b', ' B'), ' c', ' C'), ' d', ' D'), ' e', ' E'), ' f', ' F'), ' g', ' G'), ' h', ' H'), ' i', ' I'), ' j', ' J'), ' k', ' K'), ' l', ' L'), ' m', ' M'), ' n', ' N'), ' o', ' O'), ' p', ' P'), ' q', ' Q'), ' r', ' R'), ' s', ' S'), ' t', ' T'), ' u', ' U'), ' v', ' V'), ' w', ' W'), ' x', ' X'), ' y', ' Y'), ' z', ' Z')\n RETURN RIGHT(@str, LEN(@str) - 1)\nEND\nGO\n -- Code Generator for expression\nDECLARE @x INT,\n @c CHAR(1),\n @sql VARCHAR(8000)\nSET @x = 0\nSET @sql = '@str' -- actual variable/column you want to replace\nWHILE @x < 26\nBEGIN\n SET @c = CHAR(ASCII('a') + @x)\n SET @sql = 'REPLACE(' + @sql + ', '' ' + @c+ ''', '' ' + UPPER(@c) + ''')'\n SET @x = @x + 1\nEND\nPRINT @sql\n -- Code Generator for expression\nDECLARE @x INT,\n @c CHAR(1),\n @sql VARCHAR(8000),\n @count INT\nSEt @x = 0\nSET @count = 0\nSET @sql = '@str' -- actual variable you want to replace\nWHILE @x < 256\nBEGIN\n SET @c = CHAR(@x)\n -- Only generate replacement expression for characters where upper and lowercase differ\n IF @x = ASCII(LOWER(@c)) AND @x != ASCII(UPPER(@c))\n BEGIN\n SET @sql = 'REPLACE(' + @sql + ', '' ' + @c+ ''', '' ' + UPPER(@c) + ''')'\n SET @count = @count + 1\n END\n SET @x = @x + 1\nEND\nPRINT @sql\nPRINT 'Total characters substituted: ' + CONVERT(VARCHAR(255), @count)\n IF OBJECT_ID('dbo.ProperCase') IS NOT NULL\n DROP FUNCTION dbo.ProperCase\nGO\nCREATE FUNCTION dbo.PROPERCASE (\n @str VARCHAR(8000))\nRETURNS VARCHAR(8000)\nAS\nBEGIN\n SET @str = ' ' + @str\nSET @str = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@str, ' a', ' A'), ' b', ' B'), ' c', ' C'), ' d', ' D'), ' e', ' E'), ' f', ' F'), ' g', ' G'), ' h', ' H'), ' i', ' I'), ' j', ' J'), ' k', ' K'), ' l', ' L'), ' m', ' M'), ' n', ' N'), ' o', ' O'), ' p', ' P'), ' q', ' Q'), ' r', ' R'), ' s', ' S'), ' t', ' T'), ' u', ' U'), ' v', ' V'), ' w', ' W'), ' x', ' X'), ' y', ' Y'), ' z', ' Z'), ' š', ' Š'), ' œ', ' Œ'), ' ž', ' Ž'), ' à', ' À'), ' á', ' Á'), ' â', ' Â'), ' ã', ' Ã'), ' ä', ' Ä'), ' å', ' Å'), ' æ', ' Æ'), ' ç', ' Ç'), ' è', ' È'), ' é', ' É'), ' ê', ' Ê'), ' ë', ' Ë'), ' ì', ' Ì'), ' í', ' Í'), ' î', ' Î'), ' ï', ' Ï'), ' ð', ' Ð'), ' ñ', ' Ñ'), ' ò', ' Ò'), ' ó', ' Ó'), ' ô', ' Ô'), ' õ', ' Õ'), ' ö', ' Ö'), ' ø', ' Ø'), ' ù', ' Ù'), ' ú', ' Ú'), ' û', ' Û'), ' ü', ' Ü'), ' ý', ' Ý'), ' þ', ' Þ'), ' ÿ', ' Ÿ')\n RETURN RIGHT(@str, LEN(@str) - 1)\nEND\nGO\n"
},
{
"answer_id": 231705,
"author": "nathan_jr",
"author_id": 3769,
"author_profile": "https://Stackoverflow.com/users/3769",
"pm_score": 1,
"selected": false,
"text": "declare @str nvarchar(8000)\ndeclare @alpha table (low nchar(1), up nchar(1))\n\n\nset @str = 'ALL UPPER CASE and SOME lower ÄÄ ÖÖ ÜÜ ÉÉ ØØ ĈĈ ÆÆ'\n\n-- stage the alpha (needs number table)\ninsert into @alpha\n -- A-Z / a-z\n select nchar(n+32),\n nchar(n)\n from dbo.Number\n where n between 65 and 90 or\n n between 192 and 223\n\n-- append space at start of str\nset @str = lower(' ' + @str)\n\n-- upper all lower case chars preceded by space\nselect @str = replace(@str, ' ' + low, ' ' + up) \nfrom @Alpha\n\nselect @str\n"
},
{
"answer_id": 1007802,
"author": "Merritt",
"author_id": 60385,
"author_profile": "https://Stackoverflow.com/users/60385",
"pm_score": 0,
"selected": false,
"text": "create FUNCTION PROPERCASE\n(\n--The string to be converted to proper case\n@input varchar(8000)\n)\n--This function returns the proper case string of varchar type\nRETURNS varchar(8000)\nAS\nBEGIN\nIF @input IS NULL\nBEGIN\n--Just return NULL if input string is NULL\nRETURN NULL\nEND\n\n--Character variable declarations\nDECLARE @output varchar(8000)\n--Integer variable declarations\nDECLARE @ctr int, @len int, @found_at int\n--Constant declarations\nDECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int\n\n--Variable/Constant initializations\nSET @ctr = 1\nSET @len = LEN(@input)\nSET @output = ''\nSET @LOWER_CASE_a = 97\nSET @LOWER_CASE_z = 122\nSET @Delimiter = ' ,-'\nSET @UPPER_CASE_A = 65\nSET @UPPER_CASE_Z = 90\n\nWHILE @ctr <= @len\nBEGIN\n--This loop will take care of reccuring white spaces\nWHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) > 0\nBEGIN\nSET @output = @output + SUBSTRING(@input,@ctr,1)\nSET @ctr = @ctr + 1\nEND\n\nIF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a AND @LOWER_CASE_z\nBEGIN\n--Converting the first character to upper case\nSET @output = @output + UPPER(SUBSTRING(@input,@ctr,1))\nEND\nELSE\nBEGIN\nSET @output = @output + SUBSTRING(@input,@ctr,1)\nEND\n\nSET @ctr = @ctr + 1\n\nWHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 AND (@ctr <= @len)\nBEGIN\nIF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A AND @UPPER_CASE_Z\nBEGIN\nSET @output = @output + LOWER(SUBSTRING(@input,@ctr,1))\nEND\nELSE\nBEGIN\nSET @output = @output + SUBSTRING(@input,@ctr,1)\nEND\nSET @ctr = @ctr + 1\nEND\n\nEND\nRETURN @output\nEND\n\n\n\nGO\nSET QUOTED_IDENTIFIER OFF\nGO\nSET ANSI_NULLS ON\nGO\n"
},
{
"answer_id": 1764042,
"author": "Dennis Allen",
"author_id": 214691,
"author_profile": "https://Stackoverflow.com/users/214691",
"pm_score": 2,
"selected": false,
"text": "'[^a-z]' '[' + Char(32) + Char(9) + Char(13) + Char(10) + ']' CREATE FUNCTION String.InitCap( @string nvarchar(4000) ) RETURNS nvarchar(4000) AS\nBEGIN\n\n-- 1. Convert all letters to lower case\n DECLARE @InitCap nvarchar(4000); SET @InitCap = Lower(@string);\n\n-- 2. Using a Sequence, replace the letters that should be upper case with their upper case version\n SELECT @InitCap = Stuff( @InitCap, n, 1, Upper( SubString( @InitCap, n, 1 ) ) )\n FROM (\n SELECT (1 + n1.n + n10.n + n100.n + n1000.n) AS n\n FROM (SELECT 0 AS n UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) AS n1\n CROSS JOIN (SELECT 0 AS n UNION SELECT 10 UNION SELECT 20 UNION SELECT 30 UNION SELECT 40 UNION SELECT 50 UNION SELECT 60 UNION SELECT 70 UNION SELECT 80 UNION SELECT 90) AS n10\n CROSS JOIN (SELECT 0 AS n UNION SELECT 100 UNION SELECT 200 UNION SELECT 300 UNION SELECT 400 UNION SELECT 500 UNION SELECT 600 UNION SELECT 700 UNION SELECT 800 UNION SELECT 900) AS n100\n CROSS JOIN (SELECT 0 AS n UNION SELECT 1000 UNION SELECT 2000 UNION SELECT 3000) AS n1000\n ) AS Sequence\n WHERE \n n BETWEEN 1 AND Len( @InitCap )\n AND SubString( @InitCap, n, 1 ) LIKE '[a-z]' /* this character is a letter */\n AND (\n n = 1 /* this character is the first `character` */\n OR SubString( @InitCap, n-1, 1 ) LIKE '[^a-z]' /* the previous character is NOT a letter */\n )\n AND (\n n < 3 /* only test the 3rd or greater characters for this exception */\n OR SubString( @InitCap, n-2, 3 ) NOT LIKE '[a-z]''[a-z]' /* exception: The pattern <letter>'<letter> should not capatolize the letter following the apostrophy */\n )\n\n-- 3. Return the modified version of the input\n RETURN @InitCap\n\nEND\n"
},
{
"answer_id": 20660732,
"author": "Richard Sayakanit",
"author_id": 302589,
"author_profile": "https://Stackoverflow.com/users/302589",
"pm_score": 6,
"selected": false,
"text": "UPDATE titles\n SET title =\n UPPER(LEFT(title, 1)) +\n LOWER(RIGHT(title, LEN(title) - 1))\n"
},
{
"answer_id": 28712621,
"author": "Harmeet Singh Bhamra",
"author_id": 2758965,
"author_profile": "https://Stackoverflow.com/users/2758965",
"pm_score": 4,
"selected": false,
"text": "CREATE FUNCTION [dbo].[fnConvert_TitleCase] (@InputString VARCHAR(4000) )\nRETURNS VARCHAR(4000)\nAS\nBEGIN\nDECLARE @Index INT\nDECLARE @Char CHAR(1)\nDECLARE @OutputString VARCHAR(255)\n\nSET @OutputString = LOWER(@InputString)\nSET @Index = 2\nSET @OutputString = STUFF(@OutputString, 1, 1,UPPER(SUBSTRING(@InputString,1,1)))\n\nWHILE @Index <= LEN(@InputString)\nBEGIN\n SET @Char = SUBSTRING(@InputString, @Index, 1)\n IF @Char IN (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&','''','(')\n IF @Index + 1 <= LEN(@InputString)\nBEGIN\n IF @Char != ''''\n OR\n UPPER(SUBSTRING(@InputString, @Index + 1, 1)) != 'S'\n SET @OutputString =\n STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))\nEND\n SET @Index = @Index + 1\nEND\n\nRETURN ISNULL(@OutputString,'')\nEND\n select dbo.fnConvert_TitleCase(Upper('ÄÄ ÖÖ ÜÜ ÉÉ ØØ ĈĈ ÆÆ')) as test\nselect dbo.fnConvert_TitleCase(upper('Whatever the mind of man can conceive and believe, it can achieve. – Napoleon hill')) as test\n"
},
{
"answer_id": 31191399,
"author": "Kenjamarticus",
"author_id": 5074978,
"author_profile": "https://Stackoverflow.com/users/5074978",
"pm_score": 2,
"selected": false,
"text": "UPPER(substring(input_column_name,1,1)) + LOWER(substring(input_column_name, 2, len(input_column_name)-1))\n"
},
{
"answer_id": 38646988,
"author": "Alansoft",
"author_id": 3281610,
"author_profile": "https://Stackoverflow.com/users/3281610",
"pm_score": 3,
"selected": false,
"text": "CREATE FUNCTION [dbo].[fnToProperCase]( @name nvarchar(500) )\nRETURNS nvarchar(500)\nAS\nBEGIN\ndeclare @pos int = 1\n , @pos2 int\n\nif (@name <> '')--or @name = lower(@name) collate SQL_Latin1_General_CP1_CS_AS or @name = upper(@name) collate SQL_Latin1_General_CP1_CS_AS)\nbegin\n set @name = lower(rtrim(@name))\n while (1 = 1)\n begin\n set @name = stuff(@name, @pos, 1, upper(substring(@name, @pos, 1)))\n set @pos2 = patindex('%[- ''.)(]%', substring(@name, @pos, 500))\n set @pos += @pos2\n if (isnull(@pos2, 0) = 0 or @pos > len(@name))\n break\n end\nend\n\nreturn @name\nEND\nGO\n"
},
{
"answer_id": 39394049,
"author": "Vorlic",
"author_id": 4248435,
"author_profile": "https://Stackoverflow.com/users/4248435",
"pm_score": -1,
"selected": false,
"text": "SELECT UPPER('Put YoUR O'So oddLy casED McWeird-nAme von rightHERE here')"
},
{
"answer_id": 51403256,
"author": "FriskyKitty",
"author_id": 897184,
"author_profile": "https://Stackoverflow.com/users/897184",
"pm_score": 0,
"selected": false,
"text": "InitCap() SELECT ID\n ,InitCap(LastName ||', '|| FirstName ||' '|| Nvl(MiddleName,'')) AS RecipientName\nFROM SomeTable\n"
},
{
"answer_id": 51498901,
"author": "Sathish Babu",
"author_id": 10127962,
"author_profile": "https://Stackoverflow.com/users/10127962",
"pm_score": 0,
"selected": false,
"text": "Select Jobtitle,\nconcat(Upper(LEFT(jobtitle,1)), SUBSTRING(jobtitle,2,LEN(jobtitle))) as Propercase\nFrom [HumanResources].[Employee]\n"
},
{
"answer_id": 53231234,
"author": "Gabe",
"author_id": 220997,
"author_profile": "https://Stackoverflow.com/users/220997",
"pm_score": 1,
"selected": false,
"text": "STRING_SPLIT STRING_AGG STRING_AGG STUFF/XML SELECT StateName = 'North Carolina' \nINTO #States\nUNION ALL\nSELECT 'Texas'\n\n\n;WITH cteData AS \n(\n SELECT \n UPPER(LEFT(value, 1)) +\n LOWER(RIGHT(value, LEN(value) - 1)) value, op.StateName\n FROM #States op\n CROSS APPLY STRING_SPLIT(op.StateName, ' ') AS ss\n)\nSELECT \n STRING_AGG(value, ' ')\nFROM cteData c \nGROUP BY StateName\n"
},
{
"answer_id": 54932265,
"author": "reggaeguitar",
"author_id": 2125444,
"author_profile": "https://Stackoverflow.com/users/2125444",
"pm_score": 1,
"selected": false,
"text": " update tableName set columnName = \n upper(SUBSTRING(columnName, 1, 1)) + substring(columnName, 2, len(columnName)) from tableName\n"
},
{
"answer_id": 55631111,
"author": "philipnye",
"author_id": 4659442,
"author_profile": "https://Stackoverflow.com/users/4659442",
"pm_score": 2,
"selected": false,
"text": "St Elizabeth's St Elizabeth'S create function properCase(@text as varchar(8000))\nreturns varchar(8000)\nas\nbegin\n declare @reset int;\n declare @ret varchar(8000);\n declare @i int;\n declare @c char(1);\n declare @d char(1);\n\n if @text is null\n return null;\n\n select @reset = 1, @i = 1, @ret = '';\n\n while (@i <= len(@text))\n select\n @c = substring(@text, @i, 1),\n @d = substring(@text, @i+1, 1),\n @ret = @ret + case when @reset = 1 or (@reset=-1 and @c!='s') or (@reset=-1 and @c='s' and @d!=' ') then upper(@c) else lower(@c) end,\n @reset = case when @c like '[a-za-z]' then 0 when @c='''' then -1 else 1 end,\n @i = @i + 1\n return @ret\nend\n st elizabeth's St Elizabeth's o'keefe O'Keefe o'sullivan O'Sullivan"
},
{
"answer_id": 58289601,
"author": "Zexks Marquise",
"author_id": 4205675,
"author_profile": "https://Stackoverflow.com/users/4205675",
"pm_score": 1,
"selected": false,
"text": "CREATE FUNCTION ProperCase(@Text AS NVARCHAR(MAX))\nRETURNS NVARCHAR(MAX)\nAS BEGIN\n\n DECLARE @return NVARCHAR(MAX)\n\n SELECT @return = COALESCE(@return + ' ', '') + Word FROM (\n SELECT CASE\n WHEN LOWER(value) = 'llc' THEN UPPER(value)\n WHEN LOWER(value) = 'lp' THEN UPPER(value) --Add as many new special cases as needed\n ELSE\n CASE WHEN LEN(value) = 1\n THEN UPPER(value)\n ELSE UPPER(LEFT(value, 1)) + (LOWER(RIGHT(value, LEN(value) - 1)))\n END\n END AS Word\n FROM STRING_SPLIT(@Text, ' ')\n ) tmp\n\n RETURN @return\nEND\n"
},
{
"answer_id": 64435946,
"author": "cryocaustik",
"author_id": 3931046,
"author_profile": "https://Stackoverflow.com/users/3931046",
"pm_score": 2,
"selected": false,
"text": "\nwith t as (\n select 'GOOFYEAR Tire and Rubber Company' as n\n union all\n select 'THE HAPPY BEAR' as n\n union all\n select 'MONK HOUSE SALES' as n\n union all\n select 'FORUM COMMUNICATIONS' as n\n)\nselect\n n,\n (\n select ' ' + (\n upper(left(value, 1))\n + lower(substring(value, 2, 999))\n )\n from (\n select value\n from string_split(t.n, ' ')\n ) as sq\n for xml path ('')\n ) as title_cased\nfrom t\n"
},
{
"answer_id": 66825487,
"author": "JoshRoss",
"author_id": 81010,
"author_profile": "https://Stackoverflow.com/users/81010",
"pm_score": 0,
"selected": false,
"text": "CREATE OR ALTER FUNCTION dbo.ProperCase(@value varchar(MAX)) RETURNS varchar(MAX) AS \n BEGIN\n \n RETURN (SELECT STRING_AGG(CASE lv WHEN 0 THEN '' WHEN 1 THEN UPPER(value) \n ELSE UPPER(LEFT(value,1)) + LOWER(RIGHT(value,lv-1)) END,' ') \n FROM STRING_SPLIT(TRIM(@value),' ') AS ss \n CROSS APPLY (SELECT LEN(VALUE) lv) AS reuse \n WHERE @value IS NOT NULL)\n\n END\n"
},
{
"answer_id": 69184214,
"author": "Joe Shakely",
"author_id": 7537658,
"author_profile": "https://Stackoverflow.com/users/7537658",
"pm_score": 0,
"selected": false,
"text": "create function [dbo].Pascal (@string varchar(max))\nreturns varchar(max)\nas\nbegin\n declare @Index int\n ,@ResultString varchar(max)\n\n set @Index = 1\n set @ResultString = ''\n\n while (@Index < LEN(@string) + 1)\n begin\n if (@Index = 1)\n begin\n set @ResultString += UPPER(SUBSTRING(@string, @Index, 1))\n set @Index += 1\n end\n else if (\n (\n SUBSTRING(@string, @Index - 1, 1) = ' '\n or SUBSTRING(@string, @Index - 1, 1) = '-'\n or SUBSTRING(@string, @Index + 1, 1) = '-'\n )\n and @Index + 1 <> LEN(@string) + 1\n )\n begin\n set @ResultString += UPPER(SUBSTRING(@string, @Index, 1))\n set @Index += 1\n end\n else\n begin\n set @ResultString += LOWER(SUBSTRING(@string, @Index, 1))\n set @Index += 1\n end\n end\n\n if (@@ERROR <> 0)\n begin\n set @ResultString = @string\n end\n\n return replace(replace(replace(@ResultString, ' ii', ' II'), ' iii', ' III'), ' iv', ' IV')\nend\n"
},
{
"answer_id": 74368743,
"author": "David Zayn",
"author_id": 8697724,
"author_profile": "https://Stackoverflow.com/users/8697724",
"pm_score": 1,
"selected": false,
"text": "SELECT INITCAP(title) FROM data;\n SELECT dbo.InitCap(title) FROM data;\n -- Drop the function if it already exists\n IF OBJECT_ID('dbo.InitCap') IS NOT NULL\n DROP FUNCTION dbo.InitCap;\n GO\n \n -- Implementing Oracle INITCAP function\n CREATE FUNCTION dbo.InitCap (@inStr VARCHAR(8000))\n RETURNS VARCHAR(8000)\n AS\n BEGIN\n DECLARE @outStr VARCHAR(8000) = LOWER(@inStr),\n @char CHAR(1), \n @alphanum BIT = 0,\n @len INT = LEN(@inStr),\n @pos INT = 1; \n \n -- Iterate through all characters in the input string\n WHILE @pos <= @len BEGIN\n \n -- Get the next character\n SET @char = SUBSTRING(@inStr, @pos, 1);\n \n -- If the position is first, or the previous characater is not alphanumeric\n -- convert the current character to upper case\n IF @pos = 1 OR @alphanum = 0\n SET @outStr = STUFF(@outStr, @pos, 1, UPPER(@char));\n \n SET @pos = @pos + 1;\n \n -- Define if the current character is non-alphanumeric\n IF ASCII(@char) <= 47 OR (ASCII(@char) BETWEEN 58 AND 64) OR\n (ASCII(@char) BETWEEN 91 AND 96) OR (ASCII(@char) BETWEEN 123 AND 126)\n SET @alphanum = 0;\n ELSE\n SET @alphanum = 1;\n \n END\n \n RETURN @outStr; \n END\n GO\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2424/"
] |
230,186
|
<p>I am trying to aid another programmer with a page called Default.aspx with a code-behind section, and unfortunately I am at a bit of a loss.</p>
<pre><code> Partial Class _Default
Inherits OverheadClass
'A bunch of global variables here'
Private Sub page_load(ByVal sender As Object, ByVal e As System.Eventarts) Handles Me.Load
'Function goes here'
</code></pre>
<p>And in the OverheadClass we have</p>
<pre><code> Public Sub Sub_OverheadClass_Load(ByVal sender As Object, ByVal e as System.EventArgs) Handles MyClass.Load
</code></pre>
<p>The desired effect is when the OverheadClass is inherited, we want its load to run before the load event on the page runs. There is probably a very simple answer to this that I am missing.</p>
<p>Edit: I forgot to note that we write in VB, and not C# as many of you are used to for ASP.</p>
|
[
{
"answer_id": 230200,
"author": "mattruma",
"author_id": 1768,
"author_profile": "https://Stackoverflow.com/users/1768",
"pm_score": 5,
"selected": true,
"text": "protected override void OnLoad(EventArgs e)\n{\n base.OnLoad(e);\n\n // Do some stuff here\n}\n Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)\n\n MyBase.OnLoad(e)\n\n ' Do some stuff here\n\nEnd Sub\n"
},
{
"answer_id": 230217,
"author": "Brian Schmitt",
"author_id": 30492,
"author_profile": "https://Stackoverflow.com/users/30492",
"pm_score": 2,
"selected": false,
"text": "Private Sub page_load(ByVal sender As Object, ByVal e As System.Eventarts) Handles Me.Load\n Mybase.Sub_OverheadClass_Load(e)\nEnd Sub\n"
},
{
"answer_id": 230363,
"author": "Loscas",
"author_id": 22706,
"author_profile": "https://Stackoverflow.com/users/22706",
"pm_score": 0,
"selected": false,
"text": " Partial Public Class _Default\n Inherits OverheadClass\n\n Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load\n 'Do some page stuff'\n End Sub\n End Class\n Public Class OverheadClass\n Inherits System.Web.UI.Page\n Public Sub Sub_OverheadClass_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyClass.Load\n 'Do some base stuff'\n End Sub\nEnd Class\n"
},
{
"answer_id": 230432,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 0,
"selected": false,
"text": " Partial Class OverheadClass\n Inherits System.Web.UI.Page\n\n Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) \n MyBase.OnLoad(e)\n End Sub\nEnd Class\n\n\n\nPartial Class _Default\n Inherits OverheadClass\n\n Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) \n MyBase.OnLoad(e)\n End Sub\nEnd Class\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12545/"
] |
230,196
|
<p>I need write an update statement that used multiple tables to determine which rows to update, since in Oracle, multiple tables aren't allowed. The following query will return a "ORA-00971: Missing SET keyword" error</p>
<pre><code>UPDATE
TABLE1 a,
TABLE2 b
SET
a.COL1 = 'VALUE'
WHERE
a.FK = b.PK
AND b.COL2 IN ('SET OF VALUES')
</code></pre>
<p>Looking up the UPDATE statement syntax on oracle, I found the following <a href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/update_statement.htm" rel="noreferrer">link</a>, which shows that you can use a subquery in place of a table name.</p>
<p>When I tried to write the query like this, I got a "ORA-01779: Cannot modify a column which maps to a non key-preserved table"</p>
<pre><code>UPDATE
(
SELECT
a.COL1
FROM
TABLE1 a,
TABLE2 b
WHERE
a.FK = b.PK
AND b.COL2 IN ('SET OF VALUES')
) update_tbl
SET
update_tbl.COL1 = 'VALUE'
</code></pre>
<p>I did rewrite the query (show below) using an EXISTS statement instead and it works fine, but would still like to know how this is done.</p>
<pre><code>UPDATE
TABLE1 update_tbl
SET
update_tbl.COL1 = 'VALUE'
WHERE
EXISTS (
SELECT
1
FROM
TABLE1 a
TABLE2 b
WHERE
a.FK = b.PK
AND b.COL2 IN ('SET OF VALUES')
AND update_tbl.PK = a.PK
)
</code></pre>
<p>Thanks!
-Nate</p>
|
[
{
"answer_id": 230251,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 4,
"selected": true,
"text": "UPDATE TABLE1 a\nSET a.COL1 = 'VALUE'\nWHERE a.FK IN\n( SELECT b.PK FROM TABLE2 b\n WHERE b.COL2 IN ('SET OF VALUES')\n)\n UPDATE\n (\n SELECT\n a.COL1, a.PKCOL\n FROM\n TABLE1 a,\n TABLE2 b\n WHERE\n a.FK = b.PK\n AND b.COL2 IN ('SET OF VALUES')\n ) update_tbl\nSET\n update_tbl.COL1 = 'VALUE'\n"
},
{
"answer_id": 230851,
"author": "JosephStyons",
"author_id": 672,
"author_profile": "https://Stackoverflow.com/users/672",
"pm_score": 2,
"selected": false,
"text": "UPDATE\n TABLE1 update_tbl\nSET\n update_tbl.COL1 = 'VALUE'\nWHERE\n (update_tbl.PK1, update_tbl.pk2) in(\n select some_field1, some_field2\n from some_table st\n where st.some_fields = 'some conditions'\n );\n"
},
{
"answer_id": 233069,
"author": "Nick Pierpoint",
"author_id": 4003,
"author_profile": "https://Stackoverflow.com/users/4003",
"pm_score": 3,
"selected": false,
"text": "UPDATE\n TABLE1\nSET\n COL1 = 'VALUE'\nWHERE\n ROWID in\n (\n SELECT\n a.rowid\n FROM\n TABLE1 a,\n TABLE2 b\n WHERE\n a.FK = b.PK\n AND b.COL2 IN ('SET OF VALUES')\n )\n"
},
{
"answer_id": 6147880,
"author": "Franck",
"author_id": 772454,
"author_profile": "https://Stackoverflow.com/users/772454",
"pm_score": 1,
"selected": false,
"text": "DECLARE\n\n /* Output variables to hold the result of the query: */\n a T1.e%TYPE;\n b T2.f%TYPE;\n c T2.g%TYPE;\n\n /* Cursor declaration: */\n CURSOR T1Cursor IS\n SELECT T1.e, T2.f, T2.g\n FROM T1, T2\n WHERE T1.id = T2.id AND T1.e <> T2.f\n\n FOR UPDATE;\n\nBEGIN\n\n OPEN T1Cursor;\n\n LOOP\n\n /* Retrieve each row of the result of the above query\n into PL/SQL variables: */\n FETCH T1Cursor INTO a, b;\n\n /* If there are no more rows to fetch, exit the loop: */\n EXIT WHEN T1Cursor%NOTFOUND;\n\n /* Delete the current tuple: */\n DELETE FROM T1 WHERE CURRENT OF T1Cursor;\n\n /* Insert the reverse tuple: */\n INSERT INTO T1 VALUES(b, a);\n\n /* Here is my stuff using the variables to update my table */\n UPDATE T2\n SET T2.f = a\n WHERE T2.id = c;\n\n END LOOP;\n\n /* Free cursor used by the query. */\n CLOSE T1Cursor;\n\nEND;\n.\nrun;\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5129/"
] |
230,205
|
<p>I have a page that is supposed to launch the Print Preview page onload.</p>
<p>I found this:</p>
<pre><code>var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
</code></pre>
<p>But...</p>
<ol>
<li>it does not work in FireFox.</li>
<li>it's kind of ugly.</li>
</ol>
<p>Is there a better way for IE or a way that works for FireFox?</p>
|
[
{
"answer_id": 230243,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "window.print()"
},
{
"answer_id": 23774526,
"author": "Vikas Kottari",
"author_id": 2757125,
"author_profile": "https://Stackoverflow.com/users/2757125",
"pm_score": 3,
"selected": false,
"text": "<span>Main heading</span>\n<asp:Label ID=\"lbl1\" runat=\"server\" Text=\"Contents\"></asp:Label>\n<asp:Label Text=\"Contractor Name\" ID=\"lblCont\" runat=\"server\"></asp:Label>\n<div id=\"forPrintPreview\">\n <asp:Label Text=\"Company Name\" runat=\"server\"></asp:Label>\n <asp:GridView runat=\"server\">\n\n //GridView Content goes here\n\n </asp:GridView\n</div>\n\n<input type=\"button\" onclick=\"PrintPreview();\" value=\"Print Preview\" />\n function PrintPreview() {\n var Contractor= $('span[id*=\"lblCont\"]').html();\n printWindow = window.open(\"\", \"\", \"location=1,status=1,scrollbars=1,width=650,height=600\");\n printWindow.document.write('<html><head>');\n printWindow.document.write('<style type=\"text/css\">@media print{.no-print, .no-print *{display: none !important;}</style>');\n printWindow.document.write('</head><body>');\n printWindow.document.write('<div style=\"width:100%;text-align:right\">');\n\n //Print and cancel button\n printWindow.document.write('<input type=\"button\" id=\"btnPrint\" value=\"Print\" class=\"no-print\" style=\"width:100px\" onclick=\"window.print()\" />');\n printWindow.document.write('<input type=\"button\" id=\"btnCancel\" value=\"Cancel\" class=\"no-print\" style=\"width:100px\" onclick=\"window.close()\" />');\n\n printWindow.document.write('</div>');\n\n //You can include any data this way.\n printWindow.document.write('<table><tr><td>Contractor name:'+ Contractor +'</td></tr>you can include any info here</table');\n\n printWindow.document.write(document.getElementById('forPrintPreview').innerHTML);\n //here 'forPrintPreview' is the id of the 'div' in current page(aspx).\n printWindow.document.write('</body></html>');\n printWindow.document.close();\n printWindow.focus();\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27482/"
] |
230,230
|
<p>near the top of the code i see things like, </p>
<p>btn_dropdown._visible = false;
mcMenuBkg._visible = false;</p>
<p>but I can't find these assets anywhere in the library or in any code, how does this make any sense?</p>
<p>The movie clips in the library that look the same have different names and I can delete them entirely and they still show up when I compile and run, or I can add trace statements into their code and they never get called.</p>
<p>where on earth are these assets defined?</p>
|
[
{
"answer_id": 231581,
"author": "branchgabriel",
"author_id": 30807,
"author_profile": "https://Stackoverflow.com/users/30807",
"pm_score": 0,
"selected": false,
"text": "var mybutton:SimpleButton=new SimpleButton();\n"
},
{
"answer_id": 232339,
"author": "fenomas",
"author_id": 10651,
"author_profile": "https://Stackoverflow.com/users/10651",
"pm_score": 3,
"selected": true,
"text": "attachMovie()"
},
{
"answer_id": 232887,
"author": "Iain",
"author_id": 11911,
"author_profile": "https://Stackoverflow.com/users/11911",
"pm_score": 0,
"selected": false,
"text": "_visible = false\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18309/"
] |
230,241
|
<p>I have a table, call it TBL. It has two columns,call them A and B. Now in the query I require one column as A and other column should be a comma seprated list of all B's which are against A in TBL.
e.g. TBL is like this</p>
<p>1 Alpha</p>
<p>2 Beta</p>
<p>1 Gamma</p>
<p>1 Delta</p>
<p>Result of query should be </p>
<p>1 Alpha,Gamma,Delta</p>
<p>2 Beta</p>
<p>This type of thing is very easy to do with cursors in stored procedure. But I am not able to do it through MS Access, because apparently it does not support stored procedures.
Is there a way to run stored procedure in MS access? or is there a way through SQL to run this type of query</p>
|
[
{
"answer_id": 230823,
"author": "pro3carp3",
"author_id": 7899,
"author_profile": "https://Stackoverflow.com/users/7899",
"pm_score": 2,
"selected": false,
"text": "Public Sub GenerateColorList()\n\nDim cn As New ADODB.Connection\nDim Widgets As New ADODB.Recordset\nDim ColorListByWidget As New ADODB.Recordset\nDim ColorList As String\n\nSet cn = CurrentProject.Connection\n\ncn.Execute \"DELETE * FROM ColorListByWidget\"\ncn.Execute \"INSERT INTO ColorListByWidget (ID) SELECT ID FROM Widgets GROUP BY ID\"\n\nWith ColorListByWidget\n .Open \"ColorListByWidget\", cn, adOpenForwardOnly, adLockOptimistic, adCmdTable\n If Not (.BOF And .EOF) Then\n .MoveFirst\n Do Until .EOF\n Widgets.Open \"SELECT Color FROM Widgets WHERE ID = \" & .Fields(\"ID\"), cn\n If Not (.BOF And .EOF) Then\n Widgets.MoveFirst\n ColorList = \"\"\n Do Until Widgets.EOF\n ColorList = ColorList & Widgets.Fields(\"Color\").Value & \", \"\n Widgets.MoveNext\n Loop\n End If\n .Fields(\"ColorList\") = Left$(ColorList, Len(ColorList) - 2)\n .MoveNext\n Widgets.Close\n Loop\n End If\nEnd With\n\n\nEnd Sub\n"
},
{
"answer_id": 231570,
"author": "Fionnuala",
"author_id": 2548,
"author_profile": "https://Stackoverflow.com/users/2548",
"pm_score": 5,
"selected": true,
"text": "SELECT tbl.A, Concatenate(\"SELECT B FROM tbl\n WHERE A = \" & [A]) AS ConcA\nFROM tbl\nGROUP BY tbl.A\n Function Concatenate(pstrSQL As String, _\n Optional pstrDelim As String = \", \") _\n As String\n 'example\n 'tblFamily with FamID as numeric primary key\n 'tblFamMem with FamID, FirstName, DOB,...\n 'return a comma separated list of FirstNames\n 'for a FamID\n ' John, Mary, Susan\n 'in a Query\n '(This SQL statement assumes FamID is numeric)\n '===================================\n 'SELECT FamID,\n 'Concatenate(\"SELECT FirstName FROM tblFamMem\n ' WHERE FamID =\" & [FamID]) as FirstNames\n 'FROM tblFamily\n '===================================\n '\n 'If the FamID is a string then the SQL would be\n '===================================\n 'SELECT FamID,\n 'Concatenate(\"SELECT FirstName FROM tblFamMem\n ' WHERE FamID =\"\"\" & [FamID] & \"\"\"\") as FirstNames\n 'FROM tblFamily\n '===================================\n\n '======For DAO uncomment next 4 lines=======\n '====== comment out ADO below =======\n 'Dim db As DAO.Database\n 'Dim rs As DAO.Recordset\n 'Set db = CurrentDb\n 'Set rs = db.OpenRecordset(pstrSQL)\n\n '======For ADO uncomment next two lines=====\n '====== comment out DAO above ======\n Dim rs As New ADODB.Recordset\n rs.Open pstrSQL, CurrentProject.Connection, _\n adOpenKeyset, adLockOptimistic\n Dim strConcat As String 'build return string\n With rs\n If Not .EOF Then\n .MoveFirst\n Do While Not .EOF\n strConcat = strConcat & _\n .Fields(0) & pstrDelim\n .MoveNext\n Loop\n End If\n .Close\n End With\n Set rs = Nothing\n '====== uncomment next line for DAO ========\n 'Set db = Nothing\n If Len(strConcat) > 0 Then\n strConcat = Left(strConcat, _\n Len(strConcat) - Len(pstrDelim))\n End If\n Concatenate = strConcat\nEnd Function \n"
},
{
"answer_id": 231811,
"author": "Philippe Grondier",
"author_id": 11436,
"author_profile": "https://Stackoverflow.com/users/11436",
"pm_score": 0,
"selected": false,
"text": "Dim sp as string\nsp = \"your stored procedure here\" (you can load it from a text file or a memo field?)\n\nAccess.CurrentProject.AccessConnection.Execute sp\n"
},
{
"answer_id": 232792,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 0,
"selected": false,
"text": "CONCATENATE() CREATE PROCEDURE procedure (param1 datatype[, param2 datatype][, ...]) AS sqlstatement;\n\nEXECUTE procedure [param1[, param2[, ...]];\n PROCEDURE"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6613/"
] |
230,245
|
<p>Should the "visibility" for the <code>__destruct()</code> function be public or something else? I'm trying to write a standards doc for my group and this question came up.</p>
|
[
{
"answer_id": 230258,
"author": "Mark Biek",
"author_id": 305,
"author_profile": "https://Stackoverflow.com/users/305",
"pm_score": 3,
"selected": false,
"text": "<?php\nclass MyParent\n{\n private function __destruct()\n {\n echo 'Parent::__destruct';\n }\n}\n\nclass MyChild extends MyParent\n{\n function __destruct()\n {\n echo 'Child::__destruct';\n parent::__destruct();\n }\n}\n\n$myChild = new MyChild();\n?>\n"
},
{
"answer_id": 230358,
"author": "Dan Soap",
"author_id": 25253,
"author_profile": "https://Stackoverflow.com/users/25253",
"pm_score": 6,
"selected": true,
"text": "Warning: Call to protected MyChild1::__destruct() from context '' during shutdown ignored in Unknown on line 0\nWarning: Call to private MyChild2::__destruct() from context '' during shutdown ignored in Unknown on line 0\n <?php\nclass MyParent\n{\n private function __destruct()\n {\n echo 'Parent::__destruct';\n }\n}\n\nclass MyChild extends MyParent\n{\n private function __destruct()\n {\n echo 'Child::__destruct';\n parent::__destruct();\n }\n}\n\n$myChild = new MyChild();\n$myChild = null;\n$myChild = new MyChild();\n\n?>\n Fatal error: Call to private MyChild::__destruct() from context '' in D:\\www\\scratchbook\\destruct.php on line 20\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25143/"
] |
230,248
|
<p>Oracle Forms10g provides a tool to convert the Oracle Forms modules, from the binary format (.FMB) that Oracle Forms Builder works with, to text format (.FMT).</p>
<p>For example, if you create a module called <em>mymodule.fmb</em> with Oracle Forms Builder, and then invoke</p>
<pre><code>frmcmp module=mymodule.fmb script=yes batch=yes logon=no
</code></pre>
<p>from the command line, the Oracle Forms Convert utility will create a file named <em>mymodule.fmt</em> from the file <em>mymodule.fmb</em>. This text file is supposed to be "readable" by humans, except for the PL/SQL code of triggers and program units, which is codified.</p>
<p>For example, this is a snippet of a .FMT file with a chunk of codified PL/SQL code</p>
<pre><code>DEFINE F50P
BEGIN
PP = 10
PI = 3
PN = 464
PL = 1138
PV = (BLONG)
<<"
00000049 00800000 00440000 00000000 00000031 0000000d 00000002 a0011519
00002420 0000045e 001f0000 00165030 5f32335f 4f43545f 32303038 31365f33
375f3039 00000006 42454749 4e0a0000 0042676f 5f626c6f 636b2820 27504149
53455327 20293b0a 69662066 6f726d5f 73756363 65737320 7468656e 0a096578
65637574 655f7175 6572793b 0a656e64 2069663b 00000005 0a454e44 3b000000
1d574845 4e2d4e45 572d464f 524d2d49 4e535441 4e434520 28466f72 6d290000
</code></pre>
<p>Have you ever tried to decode this kind of files, to be able to extract the PL/SQL code of a form ?</p>
<p>It would be very useful to be able to search a string in the PL/SQL code of a lot of .FMT files, instead of using Oracle Forms Builder to manually open each of the corresponding .FMB files, and search the string in each one of them.</p>
<p>Thanks!</p>
|
[
{
"answer_id": 231185,
"author": "hamishmcn",
"author_id": 3590,
"author_profile": "https://Stackoverflow.com/users/3590",
"pm_score": 1,
"selected": false,
"text": "[chr(x) for x in [0x53,0x45,0x53,0x27 ,0x20,0x29,0x3b,0x0a ,0x69,0x66,0x20,0x66 ,0x6f,0x72,0x6d,0x5f ,0x73,0x75,0x63,0x63 ,0x65,0x73,0x73,0x20 ,0x74,0x68,0x65,0x6e ,0x0a,0x09,0x65,0x78]]\n ['S', 'E', 'S', \"'\", ' ', ')', ';', '\\n', 'i', 'f', ' ', 'f', 'o', 'r', 'm', '_', 's', 'u', 'c', 'c', 'e', 's', 's', ' ', 't', 'h', 'e', 'n', '\\n', '\\t', 'e', 'x']\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20037/"
] |
230,266
|
<p>Using Vim, I'm trying to pipe text selected in visual mode to a UNIX command and have the output appended to the end of the current file. For example, say we have a SQL command such as:</p>
<pre><code>SELECT * FROM mytable;
</code></pre>
<p>I want to do something like the following:</p>
<pre><code><ESC>
V " select text
:'<,'>!mysql -uuser -ppass mydb
</code></pre>
<p>But instead of having the output overwrite the currently selected text, I would like to have the output appended to the end of the file. You probably see where this is going. I'm working on using Vim as a simple SQL editor. That way, I don't have to leave Vim to edit, tweak, test SQL code.</p>
|
[
{
"answer_id": 230504,
"author": "mweerden",
"author_id": 4285,
"author_profile": "https://Stackoverflow.com/users/4285",
"pm_score": 4,
"selected": true,
"text": "q :com -range C <line1>,<line2>yank | $ | put | .,$ !rev\n :C rev"
},
{
"answer_id": 4934657,
"author": "Brad Cox",
"author_id": 100321,
"author_profile": "https://Stackoverflow.com/users/100321",
"pm_score": 0,
"selected": false,
"text": ":r | YourCommand\n :r ! echo foo\n foo"
},
{
"answer_id": 12415821,
"author": "zah",
"author_id": 35511,
"author_profile": "https://Stackoverflow.com/users/35511",
"pm_score": 1,
"selected": false,
"text": ":call append(line(\"$\"), system(\"command\", GetSelectedText()))\n GetSelectedText func! GetSelectedText()\n normal gv\"xy\n let result = getreg(\"x\")\n normal gv\n return result\nendfunc\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8243/"
] |
230,270
|
<p>I'm searching for a <strong>PHP syntax highlighting engine</strong> that can be customized (i.e. I can provide my <strong>own tokenizers</strong> for new languages) and that can handle several languages <em>simultaneously</em> (i.e. on the same output page). This engine has to work well together with <strong>CSS classes</strong>, i.e. it should format the output by inserting <code><span></code> elements that are adorned with <code>class</code> attributes. Bonus points for an extensible schema.</p>
<p>I do <em>not</em> search for a client-side syntax highlighting script (JavaScript).</p>
<p>So far, I'm stuck with <a href="http://qbnz.com/highlighter/" rel="noreferrer">GeSHi</a>. Unfortunately, GeSHi fails abysmally for several reasons. The main reason is that the different language files define completely different, inconsistent styles. I've worked hours trying to refactor the different language definitions down to a common denominator but since most definition files are in themselves quite bad, I'd finally like to switch.</p>
<p>Ideally, I'd like to have an API similar to <a href="http://coderay.rubychan.de/" rel="noreferrer">CodeRay</a>, <a href="http://pygments.org/" rel="noreferrer">Pygments</a> or the JavaScript <a href="http://code.google.com/p/syntaxhighlighter/" rel="noreferrer">dp.SyntaxHighlighter</a>.</p>
<h2>Clarification:</h2>
<p>I'm looking for a code highlighting software written <em>in</em> PHP, not <em>for</em> PHP (since I need to use it from inside PHP).</p>
|
[
{
"answer_id": 819910,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 7,
"selected": true,
"text": " <?php hyperlight($code, 'php'); ?>\n"
},
{
"answer_id": 14969976,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "Any text here.\n\n[pygments=javascript]\nvar a = function(ar1, ar2) {\n return null;\n}\n[/pygments]\n\nAny text.\n"
},
{
"answer_id": 22138962,
"author": "Taufik Nurrohman",
"author_id": 1163000,
"author_profile": "https://Stackoverflow.com/users/1163000",
"pm_score": 3,
"selected": false,
"text": "<?php\n\n/**\n * Original => http://phoboslab.org/log/2007/08/generic-syntax-highlighting-with-regular-expressions\n * Usage => `echo SyntaxHighlight::process('source code here');`\n */\n\nclass SyntaxHighlight {\n public static function process($s) {\n $s = htmlspecialchars($s);\n\n // Workaround for escaped backslashes\n $s = str_replace('\\\\\\\\','\\\\\\\\<e>', $s); \n\n $regexp = array(\n\n // Comments/Strings\n '/(\n \\/\\*.*?\\*\\/|\n \\/\\/.*?\\n|\n \\#.[^a-fA-F0-9]+?\\n|\n \\<\\!\\-\\-[\\s\\S]+\\-\\-\\>|\n (?<!\\\\\\)".*?(?<!\\\\\\)"|\n (?<!\\\\\\)\\'(.*?)(?<!\\\\\\)\\'\n )/isex' \n => 'self::replaceId($tokens,\\'$1\\')',\n\n // Punctuations\n '/([\\-\\!\\%\\^\\*\\(\\)\\+\\|\\~\\=\\`\\{\\}\\[\\]\\:\\\"\\'<>\\?\\,\\.\\/]+)/'\n => '<span class=\"P\">$1</span>',\n\n // Numbers (also look for Hex)\n '/(?<!\\w)(\n (0x|\\#)[\\da-f]+|\n \\d+|\n \\d+(px|em|cm|mm|rem|s|\\%)\n )(?!\\w)/ix'\n => '<span class=\"N\">$1</span>',\n\n // Make the bold assumption that an\n // all uppercase word has a special meaning\n '/(?<!\\w|>|\\#)(\n [A-Z_0-9]{2,}\n )(?!\\w)/x'\n => '<span class=\"D\">$1</span>',\n\n // Keywords\n '/(?<!\\w|\\$|\\%|\\@|>)(\n and|or|xor|for|do|while|foreach|as|return|die|exit|if|then|else|\n elseif|new|delete|try|throw|catch|finally|class|function|string|\n array|object|resource|var|bool|boolean|int|integer|float|double|\n real|string|array|global|const|static|public|private|protected|\n published|extends|switch|true|false|null|void|this|self|struct|\n char|signed|unsigned|short|long\n )(?!\\w|=\")/ix'\n => '<span class=\"K\">$1</span>',\n\n // PHP/Perl-Style Vars: $var, %var, @var\n '/(?<!\\w)(\n (\\$|\\%|\\@)(\\->|\\w)+\n )(?!\\w)/ix'\n => '<span class=\"V\">$1</span>'\n\n );\n\n $tokens = array(); // This array will be filled from the regexp-callback\n\n $s = preg_replace(array_keys($regexp), array_values($regexp), $s);\n\n // Paste the comments and strings back in again\n $s = str_replace(array_keys($tokens), array_values($tokens), $s);\n\n // Delete the \"Escaped Backslash Workaround Token\" (TM)\n // and replace tabs with four spaces.\n $s = str_replace(array('<e>', \"\\t\"), array('', ' '), $s);\n\n return '<pre><code>' . $s . '</code></pre>';\n }\n\n // Regexp-Callback to replace every comment or string with a uniqid and save\n // the matched text in an array\n // This way, strings and comments will be stripped out and wont be processed\n // by the other expressions searching for keywords etc.\n private static function replaceId(&$a, $match) {\n $id = \"##r\" . uniqid() . \"##\";\n\n // String or Comment?\n if(substr($match, 0, 2) == '//' || substr($match, 0, 2) == '/*' || substr($match, 0, 2) == '##' || substr($match, 0, 7) == '<!--') {\n $a[$id] = '<span class=\"C\">' . $match . '</span>';\n } else {\n $a[$id] = '<span class=\"S\">' . $match . '</span>';\n }\n return $id;\n }\n}\n\n?>\n <?php require 'generic-syntax-highlighter.php'; ?>\n<pre><code><?php echo SH('<div class=\"foo\"></div>'); ?></code></pre>\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1968/"
] |
230,285
|
<p>I am using C#. By default, when I add a web form in Visual Studio 2008 with or without a master page, the AutoEventWireup attribute is set to true in the page directive. This attribute is also set to true inside the master page master directive.</p>
<p>What value should I have AutoEventWireup set to (true/false)?</p>
<p>What are the pros and cons of both values?</p>
<p>Any help is greatly appreciated.</p>
<p>Thank you.</p>
|
[
{
"answer_id": 231689,
"author": "NathanD",
"author_id": 30544,
"author_profile": "https://Stackoverflow.com/users/30544",
"pm_score": 1,
"selected": false,
"text": "protected override void OnLoad(EventArgs e)\n{\n base.OnLoad(e); \n}\n protected void Page_Load(object sender, EventArgs e)\n{\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24522/"
] |
230,299
|
<p>I am trying to get center of parent form, not center of screen behavior.
Passing in the parent form seems to only control the ownership of the window.
These classes are sealed, so I do not see how I can do any WinProc tricks.
Rewriting the classes is not an appealing option.
Any other ideas?</p>
|
[
{
"answer_id": 230370,
"author": "tafa",
"author_id": 22186,
"author_profile": "https://Stackoverflow.com/users/22186",
"pm_score": 0,
"selected": false,
"text": "System.Windows.Forms.Form f = new Form();\nf.StartPosition = FormStartPosition.CenterParent;\n"
},
{
"answer_id": 230509,
"author": "Coderer",
"author_id": 26286,
"author_profile": "https://Stackoverflow.com/users/26286",
"pm_score": 0,
"selected": false,
"text": "Interaction.InputBox sealed"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230299",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14841/"
] |
230,335
|
<p>I started a Rails project recently and decided to use RESTful controllers. I created controllers for my key entities (such as Country) and added <code>index</code>, <code>new</code>, <code>edit</code>, <code>create</code>, <code>show</code>, <code>update</code> and <code>delete</code>. I added my <code>map.resources :country</code> to my routes file and life was good.</p>
<p>After development progressed a little, I started to encounter problems. I sometimes needed extra actions in my controller. First there was the <code>search</code> action that returned the options for my fancy autocompleting search box. Then came the need to display the countries in two different ways in different places in the application (the data displayed was different too, so it wasn't just two views) - I added the <code>index_full</code> action. Then I wanted to show a country by name in the URL, not by id so I added the <code>show_by_name</code> action.</p>
<p>What do you do when you need actions beyond the standard <code>index</code>, <code>new</code>, <code>edit</code>, <code>create</code>, <code>show</code>, <code>update</code>, <code>delete</code> in a RESTful controller in Rails? Do I need to add (and maintain) manual routes in the routes.rb file (which is a pain), do they go in a different controller, do I become unRESTful or am I missing something fundamental?</p>
<p>I guess I am asking, do I need to work harder and add actions into my routes.rb file for the privilege of being RESTful? If I wasn't using <code>map.resources</code> to add the REST goodies, the standard <code>:controller/:action, :controller/:action/:id</code> routes would handle pretty much everything automatically.</p>
|
[
{
"answer_id": 230523,
"author": "Codebeef",
"author_id": 12037,
"author_profile": "https://Stackoverflow.com/users/12037",
"pm_score": 4,
"selected": true,
"text": "map.resources :events, :collection => { :search => :get }\n"
},
{
"answer_id": 230695,
"author": "Dave Nolan",
"author_id": 9474,
"author_profile": "https://Stackoverflow.com/users/9474",
"pm_score": 4,
"selected": false,
"text": "search index /resources/index # normal index\n/resources/index?query=foo # search for 'foo'\n before_filter :do_some_preprocessing_on_parameters\n\ndef index\n @resources = Resource.find_by_param(@preprocessed_params)\nend\n index_full search_by_name /:controller/:action/:id"
},
{
"answer_id": 961916,
"author": "Omar Qureshi",
"author_id": 84018,
"author_profile": "https://Stackoverflow.com/users/84018",
"pm_score": 0,
"selected": false,
"text": "http://example1.somesite.com/example_2/foo/bar/1\n /:controller/:action/:id\n map.connect 'foo'"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230335",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16779/"
] |
230,348
|
<p>I see Oracle procedures sometimes written with "AS", and sometimes with "IS" keyword. </p>
<pre><code>CREATE OR REPLACE Procedure TESTUSER.KILLINSTANCE (INSTANCEID integer) **AS**
...
</code></pre>
<p>vs.</p>
<pre><code>CREATE OR REPLACE Procedure TESTUSER.KILLINSTANCE (INSTANCEID integer) **IS**
...
</code></pre>
<p>Is there any difference between the two?</p>
<p><hr>
Edit: Apparently, there is no functional difference between the two, but some people follow a convention to use "AS" when the SP is part of a package and "IS" when it is not. Or the other way 'round. Meh.</p>
|
[
{
"answer_id": 239256,
"author": "Nick Pierpoint",
"author_id": 4003,
"author_profile": "https://Stackoverflow.com/users/4003",
"pm_score": 6,
"selected": false,
"text": "cursor test_cursor\nis\nselect * from emp;\n cursor test_cursor\nas\nselect * from emp;\n"
},
{
"answer_id": 23082694,
"author": "StuartLC",
"author_id": 314291,
"author_profile": "https://Stackoverflow.com/users/314291",
"pm_score": 4,
"selected": false,
"text": "CREATE TYPE someRecordType AS OBJECT\n(\n SomeCol VARCHAR2(12 BYTE)\n);\n loose AS IS CREATE OR REPLACE TYPE someTableType\n IS {or AS} TABLE OF someRecordType;\n IS CREATE OR REPLACE PACKAGE SomePackage IS\n TYPE packageTableType IS TABLE OF someRecordType;\nEND SomePackage;\n AS"
},
{
"answer_id": 49369761,
"author": "Dániel Sándor",
"author_id": 5137315,
"author_profile": "https://Stackoverflow.com/users/5137315",
"pm_score": 1,
"selected": false,
"text": "AS IS"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/227/"
] |
230,351
|
<p>When I am creating a new database table, what factors should I take into account for selecting the primary key's data type?</p>
|
[
{
"answer_id": 232985,
"author": "Philippe Grondier",
"author_id": 11436,
"author_profile": "https://Stackoverflow.com/users/11436",
"pm_score": 5,
"selected": true,
"text": "'id_MyTable' 'id_myManyToManyTable' Tbl_whatever\n\n id_whatever, unique identifier, primary key\n code_whatever, whateverTypeYouWant(whateverLengthYouEstimateTheRightOne), indexed\n .....\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5618/"
] |
230,364
|
<p>I'm trying to link an RPATH containing the special string $ORIGIN into an executable built using GCC with the Code::Blocks IDE. I've specified</p>
<pre><code>-Wl,-R$ORIGIN
</code></pre>
<p>in the linker options for the project, but the command line output to GCC is wrong (stripped for clarity):</p>
<pre><code>g++ -Wl,-R
</code></pre>
<p>What is the correct way to specify this argument for Code::Blocks?</p>
|
[
{
"answer_id": 230376,
"author": "kbluck",
"author_id": 13402,
"author_profile": "https://Stackoverflow.com/users/13402",
"pm_score": 6,
"selected": true,
"text": "-Wl,-R\\$ORIGIN\n -Wl,-R\\\\$$ORIGIN\n -Wl,-R\\\\$ORIGIN\n -Wl,-R\\$ORIGIN\n"
},
{
"answer_id": 1500980,
"author": "user44538",
"author_id": 44538,
"author_profile": "https://Stackoverflow.com/users/44538",
"pm_score": 4,
"selected": false,
"text": "-Wl,-R,'$$ORIGIN/../lib'\n"
},
{
"answer_id": 14385281,
"author": "greggo",
"author_id": 450000,
"author_profile": "https://Stackoverflow.com/users/450000",
"pm_score": 1,
"selected": false,
"text": "setenv LD_RUN_PATH='$ORIGIN/../lib' #!/bin/sh\nexec /usr/bin/ld -R '$ORIGIN/../lib' \"$@\"\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230364",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13402/"
] |
230,382
|
<p>The print functionality of Excel (using VBA) is extremely slow. I'm hoping someone has a way of speeding the printing up (without using the Excel 4 Macro trick). Here's how I do it now:</p>
<pre><code>Application.ScreenUpdating = False
With ActiveSheet.PageSetup
-various setup statements which I've already minimized-
End With
ActiveSheet.PrintOut
Application.ScreenUpdating = True
</code></pre>
|
[
{
"answer_id": 231145,
"author": "Mike Rosenblum",
"author_id": 10429,
"author_profile": "https://Stackoverflow.com/users/10429",
"pm_score": 4,
"selected": true,
"text": "Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Dim origScreenUpdating As Boolean\norigScreenUpdating = Application.ScreenUpdating\nApplication.ScreenUpdating = False\n\nDim origCalcMode As xlCalculation\norigCalcMode = Application.Calculation\nApplication.Calculation = xlCalculationManual\n\nWith ActiveSheet.PageSetup\n If .PrintHeadings <> False Then .PrintHeadings = False\n If .PrintGridlines <> False Then .PrintGridlines = False\n If .PrintComments <> xlPrintNoComments Then .PrintComments = xlPrintNoComments\n ' Etc...\nEnd With\n\nApplication.ScreenUpdating = origScreenUpdating\nApplication.Calculation = origCalcMode\n"
},
{
"answer_id": 866391,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "Public Sub CopyPageSetupToAll(ByRef SourceSheet As Worksheet)\n ' Raise error if invalid source sheet is passed to procedure\n '\n If (SourceSheet Is Nothing) Then\n Err.Raise _\n Number:=vbErrorObjectVariableNotSet, _\n Source:=\"CopyPageSetupToAll\", _\n Description:=\"Unable to copy Page Setup settings: \" _\n & \"invalid reference to source sheet.\"\n Exit Sub\n End If\n\n SourceSheet.Activate\n\n With SourceSheet.PageSetup\n ' ...\n ' place PageSetup customizations here\n ' ...\n End With\n\n SourceSheet.Parent.Worksheets.Select\n Application.SendKeys \"{ENTER}\", True\n Application.Dialogs(xlDialogPageSetup).Show\nEnd Sub\n Public Sub CopyPageSetupToAll(ByRef SourceBook As Workbook)\n Dim tempSheet As Worksheet\n\n ' Raise error if invalid workbook is passed to procedure\n '\n If (SourceBook Is Nothing) Then\n Err.Raise _\n Number:=vbErrorObjectVariableNotSet, _\n Source:=\"CopyPageSetupToAll\", _\n Description:=\"Unable to copy Page Setup settings: \" _\n & \"invalid reference to source workbook.\"\n Exit Sub\n End If\n\n Set tempSheet = SourceBook.Worksheets.Add\n\n tempSheet.Activate\n\n With tempSheet.PageSetup\n ' ...\n ' place PageSetup customizations here\n ' ...\n End With\n\n SourceBook.Worksheets.Select\n Application.SendKeys \"{ENTER}\", True\n Application.Dialogs(xlDialogPageSetup).Show\n tempSheet.Delete\n\n Set tempSheet = Nothing\nEnd Sub\n SendKeys() Application.Dialogs"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13295/"
] |
230,389
|
<p>I am new to jmock and trying to mock an HttpSession. I am getting:</p>
<p>java.lang.AssertionError: unexpected invocation: httpServletRequest.getSession()
no expectations specified: did you...
- forget to start an expectation with a cardinality clause?
- call a mocked method to specify the parameter of an expectation?</p>
<p>the test method:</p>
<p>@Test</p>
<pre><code>public void testDoAuthorization(){
final HttpServletRequest request = context.mock(HttpServletRequest.class);
final HttpSession session = request.getSession();
context.checking(new Expectations(){{
one(request).getSession(true); will(returnValue(session));
}});
assertTrue(dwnLoadCel.doAuthorization(session));
}
</code></pre>
<p>I have done a bit of searching and it isn't clear to me still how this is done. Feels like I am missing some small piece. Anyone with experience in this can just point me in the right direction.
thanks</p>
|
[
{
"answer_id": 230471,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 1,
"selected": false,
"text": "final HttpServletRequest request = context.mock(HttpServletRequest.class);\n\ncontext.checking(new Expectations(){{\n one(request).getSession(true); will(returnValue(session));\n}});\n\nfinal HttpSession session = request.getSession();\n dwnLoadCel HttpSession dwnLoadCel dwnLoadCel Map"
},
{
"answer_id": 231134,
"author": "Kris Pruden",
"author_id": 16977,
"author_profile": "https://Stackoverflow.com/users/16977",
"pm_score": 3,
"selected": true,
"text": "dwnLoadCel.doAuthorization() HttpSession public void testDoAuthorization(){\n final HttpSession session = context.mock(HttpSession.class);\n\n context.checking(new Expectations(){{\n // ???\n }});\n\n assertTrue(dwnLoadCel.doAuthorization(session));\n session doAuthorization true"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3034/"
] |
230,397
|
<p>I am writing a DB upgrade script that will check to see if an index has the right two columns defined. If it doesn't, or if it only has one of them, then I will DROP it (is there a way to ALTER an index?) and then recreate it with both.</p>
|
[
{
"answer_id": 230442,
"author": "Ed Altorfer",
"author_id": 26552,
"author_profile": "https://Stackoverflow.com/users/26552",
"pm_score": 4,
"selected": true,
"text": "IF EXISTS\n(\n SELECT MyIndex.Name AS IndexName, \n Columns.name AS ColumnName \n FROM sys.indexes MyIndex\n INNER JOIN sys.index_columns IndexColumns \n ON MyIndex.index_id = IndexColumns.index_id\n AND MyIndex.object_id = IndexColumns.object_id \n INNER JOIN sys.columns Columns\n ON Columns.column_id = IndexColumns.column_id \n AND IndexColumns.object_id = Columns.object_id \n WHERE Columns.name = 'ColumnName'\n AND MyIndex.Name='IX_MyIndexName'\n)\n"
},
{
"answer_id": 230567,
"author": "skb",
"author_id": 14101,
"author_profile": "https://Stackoverflow.com/users/14101",
"pm_score": 2,
"selected": false,
"text": "\nIF EXISTS\n(\n SELECT i.Name AS IndexName, c.Name AS ColumnName\n FROM sys.indexes i\n JOIN sys.index_columns ic\n ON i.object_id = ic.object_id AND i.index_id = ic.index_id\n JOIN sys.columns c\n ON ic.object_id = c.object_id AND c.column_id = ic.column_id\n WHERE c.Name = 'MyColumnName' AND i.Name='MyIndexName'\n)\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14101/"
] |
230,401
|
<p>I'm trying to use jQuery to get data from an ASP.NET web service (SharePoint Server 2007 lists.asmx), but any call to a web service will really help as a first step in that direction.</p>
|
[
{
"answer_id": 230408,
"author": "mohammedn",
"author_id": 29268,
"author_profile": "https://Stackoverflow.com/users/29268",
"pm_score": 3,
"selected": false,
"text": "$.get(\"http://domain.com/webservice.asmx\", { name: \"John\", time: \"2pm\" },\n function(data){\n alert(\"Data Loaded: \" + data);\n });\n"
},
{
"answer_id": 230605,
"author": "Herb Caudill",
"author_id": 239663,
"author_profile": "https://Stackoverflow.com/users/239663",
"pm_score": 2,
"selected": false,
"text": "<WebMethod()>"
},
{
"answer_id": 485536,
"author": "Bobby Borszich",
"author_id": 35585,
"author_profile": "https://Stackoverflow.com/users/35585",
"pm_score": 7,
"selected": true,
"text": "function InfoByDate(sDate, eDate){\n var divToBeWorkedOn = \"#AjaxPlaceHolder\";\n var webMethod = \"http://MyWebService/Web.asmx/GetInfoByDates\";\n var parameters = \"{'sDate':'\" + sDate + \"','eDate':'\" + eDate + \"'}\";\n\n $.ajax({\n type: \"POST\",\n url: webMethod,\n data: parameters,\n contentType: \"application/json; charset=utf-8\",\n dataType: \"json\",\n success: function(msg) {\n $(divToBeWorkedOn).html(msg.d);\n },\n error: function(e){\n $(divToBeWorkedOn).html(\"Unavailable\");\n }\n });\n}\n"
},
{
"answer_id": 6921657,
"author": "Kaveh",
"author_id": 875855,
"author_profile": "https://Stackoverflow.com/users/875855",
"pm_score": 2,
"selected": false,
"text": "$.ajax({\n type: 'POST',\n url: 'data.asmx/getText',\n data: {'argInput' : 'input arg(s)'},\n complete: function(xData, status) {\n $('#txt').html($(xData.responseXML).text()); // result\n }\n});\n"
},
{
"answer_id": 16394477,
"author": "Vadim Gremyachev",
"author_id": 1375553,
"author_profile": "https://Stackoverflow.com/users/1375553",
"pm_score": 1,
"selected": false,
"text": "<script type=\"text/javascript\" src=\"filelink/jquery-1.6.1.min.js\"></script>\n<script type=\"text/javascript\" src=\"filelink/jquery.SPServices-0.6.2.min.js\"></script>\n<script language=\"javascript\" type=\"text/javascript\">\n\n$(document).ready(function() {\n $().SPServices({\n operation: \"GetListItems\",\n async: false,\n listName: \"Announcements\",\n CAMLViewFields: \"<ViewFields><FieldRef Name='Title' /></ViewFields>\",\n completefunc: function (xData, Status) {\n $(xData.responseXML).SPFilterNode(\"z:row\").each(function() {\n var liHtml = \"<li>\" + $(this).attr(\"ows_Title\") + \"</li>\";\n $(\"#tasksUL\").append(liHtml);\n });\n }\n });\n});\n</script>\n<ul id=\"tasksUL\"/>\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30867/"
] |
230,407
|
<p>I'm looking for the equivalent of right clicking on the drive in windows and seeing the disk space used and remaining info.</p>
|
[
{
"answer_id": 230412,
"author": "Zebra North",
"author_id": 17440,
"author_profile": "https://Stackoverflow.com/users/17440",
"pm_score": 6,
"selected": true,
"text": "du df"
},
{
"answer_id": 230608,
"author": "German",
"author_id": 19136,
"author_profile": "https://Stackoverflow.com/users/19136",
"pm_score": 2,
"selected": false,
"text": "s h *"
},
{
"answer_id": 230684,
"author": "Paulo Delgado",
"author_id": 1864,
"author_profile": "https://Stackoverflow.com/users/1864",
"pm_score": 3,
"selected": false,
"text": "du -sh * | sort -nr | less"
},
{
"answer_id": 10416368,
"author": "Jens",
"author_id": 648658,
"author_profile": "https://Stackoverflow.com/users/648658",
"pm_score": 1,
"selected": false,
"text": " apropos disk # And pray your admin maintains the whatis database\n"
},
{
"answer_id": 22952942,
"author": "DB Prasad",
"author_id": 2841447,
"author_profile": "https://Stackoverflow.com/users/2841447",
"pm_score": 3,
"selected": false,
"text": "df -g .\n"
},
{
"answer_id": 24916672,
"author": "Scott Prokopetz",
"author_id": 3854360,
"author_profile": "https://Stackoverflow.com/users/3854360",
"pm_score": 0,
"selected": false,
"text": "df -tk\n"
},
{
"answer_id": 41590375,
"author": "Atspulgs",
"author_id": 3540514,
"author_profile": "https://Stackoverflow.com/users/3540514",
"pm_score": 2,
"selected": false,
"text": "lsvg rootvg\n lsvgfs rootvg\n df\n chfs -a size=+1G /home\n"
},
{
"answer_id": 41858755,
"author": "Cristian",
"author_id": 5792801,
"author_profile": "https://Stackoverflow.com/users/5792801",
"pm_score": 1,
"selected": false,
"text": "su -sm ./*"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/700/"
] |
230,409
|
<p>In my <a href="https://stackoverflow.com/questions/222442/sql-server-running-large-script-files">eternal</a> <a href="https://stackoverflow.com/questions/224830/how-do-i-set-a-sql-server-scripts-timeout-from-within-the-script">saga</a> to insert 1.4 million rows of data from a SQL script, I've written a basic WinForms app that takes each line of the script and executes it individually.</p>
<p>However, because the original script contained</p>
<pre><code>SET IDENTITY_INSERT [Table] OFF
</code></pre>
<p>and SET is a session-wide command, this setting is getting lost on every SQL call, meaning that each line is failing. Is there a way to set IDENTITY_INSERT off for the whole table, database-wide just so I can make these individual calls without them failing? Or perhaps I can tell it to ignore the identity specification by appending a command to each line?</p>
|
[
{
"answer_id": 230489,
"author": "StingyJack",
"author_id": 16391,
"author_profile": "https://Stackoverflow.com/users/16391",
"pm_score": 0,
"selected": false,
"text": "SET IDENTITY_INSERT [Table] OFF;\nINSERT INTO TABLE VALUES (1, 'a');\nINSERT INTO TABLE VALUES (2, 'b');\nINSERT INTO TABLE VALUES (3, 'c');\nINSERT INTO TABLE VALUES (4, 'd');\nINSERT INTO TABLE VALUES (5, 'e');\nSET IDENTITY_INSERT [Table] ON;\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/192/"
] |
230,411
|
<p>I want yo use the EXSLT - DYN:EVALUATE in a style sheet. I have added the names pace but I don't know where the .xsl file I need to import is. I don't believe I have XALAN installed to point the import to. How would I install this? Once installed and I point it to the .xsl will it pick up the function and apply it? I am running Windows. The XSLT file is included at the top of the XML document.</p>
<p>Thanks</p>
<p>Pete</p>
|
[
{
"answer_id": 232526,
"author": "GerG",
"author_id": 17249,
"author_profile": "https://Stackoverflow.com/users/17249",
"pm_score": 4,
"selected": true,
"text": "<root>\n<foo>I am foo</foo> \n<bar>I am bar</bar> \n</root>\n <xsl:stylesheet version=\"1.0\"\n xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" \n xmlns:dyn=\"http://exslt.org/dynamic\"\n extension-element-prefixes=\"dyn\">\n\n <xsl:param name=\"path\"/>\n\n <xsl:output method=\"text\"/>\n\n <xsl:template match=\"/\">\n <xsl:value-of select=\"dyn:evaluate($path)\"/>\n </xsl:template>\n\n</xsl:stylesheet>\n xalan.exe -p path '/root/foo' input.xml dyn_evaluate.xsl\n I am foo\n I am bar\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230411",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
230,427
|
<p>Looking to hear from people who are using WCF in an enterprise environment.</p>
<p>What were the major hurdles with the roll out?
Performance issues?
Any and all tips appreciated!</p>
<p>Please provide some general statistics and server configs if you can!</p>
|
[
{
"answer_id": 230526,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 1,
"selected": false,
"text": "[NetDataContract]"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230427",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
230,449
|
<p>I have a Stored Procedure that rolls-back a series of operations. I want to call this from within another SP.</p>
<p>The problem is that the inner SP returns a record set with a single value that indicates the degree of success. </p>
<p> This approach worked well and has some advantages in our context, but in retrospect, I would have done it the conventional way with a Return value or an Output parameter. </p>
<p>I <em>could</em> always change this SP to use this approach and modify the calling code, but a) I don't want to dabble with any more code than I have to, and b) at an intellectual level, I'm curious to see what alternative solution there may be, if any.</p>
<p>How (if at all) can I call this SP and determine the value of the singleton recordset returned?</p>
<p>Thanks</p>
|
[
{
"answer_id": 230821,
"author": "hova",
"author_id": 2170,
"author_profile": "https://Stackoverflow.com/users/2170",
"pm_score": 1,
"selected": false,
"text": "CREATE TABLE #outsidetable (...)\nexec spInsideProcedure\nSELECT * FROM #outsidetable\n INSERT INTO #outsidetable SELECT <blah blah blah>\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6898/"
] |
230,454
|
<p>What would be the best way to fill an array from user input?</p>
<p>Would a solution be showing a prompt message and then get the values from from the user?</p>
|
[
{
"answer_id": 230463,
"author": "Patrick Desjardins",
"author_id": 13913,
"author_profile": "https://Stackoverflow.com/users/13913",
"pm_score": 7,
"selected": true,
"text": "string []answer = new string[10];\nfor(int i = 0;i<answer.length;i++)\n{\n answer[i]= Console.ReadLine();\n}\n"
},
{
"answer_id": 230485,
"author": "Ed Altorfer",
"author_id": 26552,
"author_profile": "https://Stackoverflow.com/users/26552",
"pm_score": 2,
"selected": false,
"text": "using Microsoft.VisualBasic;\n List<string> responses = new List<string>();\nstring response = \"\";\n\nwhile(!(response = Interaction.InputBox(\"Please enter your information\",\n \"Window Title\",\n \"Default Text\",\n xPosition,\n yPosition)).equals(\"\"))\n{\n responses.Add(response);\n}\n\nresponses.ToArray();\n"
},
{
"answer_id": 230583,
"author": "Coderer",
"author_id": 26286,
"author_profile": "https://Stackoverflow.com/users/26286",
"pm_score": 3,
"selected": false,
"text": "string foo = Console.ReadLine();\nstring[] tokens = foo.Split(\",\");\nList<int> nums = new List<int>();\nint oneNum;\nforeach(string s in tokens)\n{\n if(Int32.TryParse(s, out oneNum))\n nums.Add(oneNum);\n}\n"
},
{
"answer_id": 230781,
"author": "Stefan",
"author_id": 30604,
"author_profile": "https://Stackoverflow.com/users/30604",
"pm_score": 2,
"selected": false,
"text": "array[i] = Convert.ToDouble(Console.Readline());\n"
},
{
"answer_id": 231047,
"author": "arin",
"author_id": 30858,
"author_profile": "https://Stackoverflow.com/users/30858",
"pm_score": 2,
"selected": false,
"text": " static void Main()\n {\n double[] array = new double[6];\n Console.WriteLine(\"Please Sir Enter 6 Floating numbers\");\n for (int i = 0; i < 6; i++)\n {\n array[i] = Convert.ToDouble(Console.ReadLine());\n }\n\n double sum = 0;\n\n foreach (double d in array)\n {\n sum += d;\n }\n double average = sum / 6;\n Console.WriteLine(\"===============================================\");\n Console.WriteLine(\"The Values you've entered are\");\n Console.WriteLine(\"{0}{1,8}\", \"index\", \"value\");\n for (int counter = 0; counter < 6; counter++)\n Console.WriteLine(\"{0,5}{1,8}\", counter, array[counter]);\n Console.WriteLine(\"===============================================\");\n Console.WriteLine(\"The average is ;\");\n Console.WriteLine(average);\n Console.WriteLine(\"===============================================\");\n Console.WriteLine(\"would you like to search for a certain elemnt ? (enter yes or no)\");\n string answer = Console.ReadLine();\n switch (answer)\n {\n case \"yes\":\n Console.WriteLine(\"===============================================\");\n Console.WriteLine(\"please enter the array index you wish to get the value of it\");\n int index = Convert.ToInt32(Console.ReadLine());\n Console.WriteLine(\"===============================================\");\n Console.WriteLine(\"The Value of the selected index is:\");\n Console.WriteLine(array[index]);\n break;\n\n case \"no\":\n Console.WriteLine(\"===============================================\");\n Console.WriteLine(\"HAVE A NICE DAY SIR\");\n break;\n }\n }\n"
},
{
"answer_id": 231208,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "out out for (int counter = 0; counter < 6; counter++)\n Console.WriteLine(\"{0,5}{1,8}\", counter, array[counter]);\n for (int counter = 0; counter < 6; counter++)\n{\n Console.WriteLine(\"{0,5}{1,8}\", counter, array[counter]);\n}\n for (int counter = 0; counter < 6; counter++)\n Console.WriteLine(\"{0,5}{1,8}\", counter, array[counter]);\n Console.WriteLine(\"----\"); // This isn't part of the for loop!\n default bool keepGoing = true;\nwhile (keepGoing)\n{\n switch (answer)\n {\n case \"yes\":\n Console.WriteLine(\"===============================================\");\n Console.WriteLine(\"please enter the array index you wish to get the value of it\");\n int index = Convert.ToInt32(Console.ReadLine());\n Console.WriteLine(\"===============================================\");\n Console.WriteLine(\"The Value of the selected index is:\");\n Console.WriteLine(array[index]);\n keepGoing = false;\n break;\n\n case \"no\":\n Console.WriteLine(\"===============================================\");\n Console.WriteLine(\"HAVE A NICE DAY SIR\");\n keepGoing = false;\n break;\n\n default:\n Console.WriteLine(\"Sorry, I didn't understand that. Please enter yes or no\");\n break;\n }\n}\n // Or decimal, of course, if you've made the earlier selected change\ndouble sum = input.Sum();\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30858/"
] |
230,467
|
<p>One of my developers has started using RegexBuddy for help in interpreting legacy code, which is a usage I fully understand and support. What concerns me is using a regex tool for writing new code. I have actually discouraged its use for new code in my team. Two quotes come to mind:</p>
<blockquote>
<p><strong>Some people, when confronted with a
problem, think "I know, I’ll use
regular expressions." Now they have
two problems.</strong> - Jamie Zawinski</p>
</blockquote>
<p>And:</p>
<blockquote>
<p><strong>Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as
cleverly as possible, you are, by
definition, not smart enough to debug
it.</strong> - Brian Kernighan</p>
</blockquote>
<p>My concerns are (respectively:) </p>
<ul>
<li><p>That the tool may make it possible to solve a problem using a complicated regular expression that really doesn't need it. (See also <a href="https://stackoverflow.com/questions/230304/under-what-situations-are-regular-expressions-really-the-best-way-to-solve-the">this question</a>).</p></li>
<li><p>That my one developer, using regex tools, will start writing regular expressions which (even with comments) can't be maintained by anyone who doesn't have (and know how to use) regex tools.</p></li>
</ul>
<p>Should I encourage or discourage the use of regex tools, specifically with regard to producing new code? Are my concerns justified? Or am I being paranoid?</p>
|
[
{
"answer_id": 230483,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 2,
"selected": false,
"text": "(less|more)"
},
{
"answer_id": 232327,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 0,
"selected": false,
"text": "Expression Match Reason\n^ Pos 0 Start of input\n\\s+ \" \" At least one space\n(abs|floor|ceil) ceil One of \"abs\", \"floor\", or \"ceil\"\n...\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] |
230,517
|
<p>Please don't answer the obvious, but what are the limit signs that tell us a problem should not be solved using regular expressions?</p>
<p>For example: Why is a complete email validation too complex for a regular expression?</p>
|
[
{
"answer_id": 230548,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 4,
"selected": false,
"text": "(())()\n"
},
{
"answer_id": 230576,
"author": "Miserable Variable",
"author_id": 18573,
"author_profile": "https://Stackoverflow.com/users/18573",
"pm_score": -1,
"selected": false,
"text": "+complex AND +\"regular expression\" .*Buffer.*Window and .*Window.*Buffer"
},
{
"answer_id": 230578,
"author": "mmcdole",
"author_id": 2635,
"author_profile": "https://Stackoverflow.com/users/2635",
"pm_score": 3,
"selected": false,
"text": "\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b\n (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"\n(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x\n0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9]\n(?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.)\n{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\n\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230517",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13787/"
] |
230,522
|
<p>I have a table with multiple rows. Each row is a form. I want to use JQuery to submit all the forms that have the check box checked. The form is posting to an IFrame so there is not much need for AJAX.</p>
<p>So far I have:</p>
<pre><code> $("form").submit();
</code></pre>
<p>which submits the form. but all forms. There is arbritary number of rows, could be 80-100.</p>
|
[
{
"answer_id": 230540,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 0,
"selected": false,
"text": "$(\"td > input:checked > form\").submit();\n"
},
{
"answer_id": 230551,
"author": "Nathan Strutz",
"author_id": 5918,
"author_profile": "https://Stackoverflow.com/users/5918",
"pm_score": 3,
"selected": true,
"text": "$(\"input:checked\").parent(\"form\").submit();\n"
},
{
"answer_id": 230579,
"author": "Jeremy B.",
"author_id": 28567,
"author_profile": "https://Stackoverflow.com/users/28567",
"pm_score": 1,
"selected": false,
"text": "var formElements = $(\"form\").find(\"input:checked\").parent(\"td\").serialize();\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230522",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3208/"
] |
230,525
|
<p>I have started making a database and I have an 'ordered item' and a 'invoice' table. I would like to find out how I would add up the prices of the items that the customer picks. As well where abouts do you put this 'rule' on the database. </p>
|
[
{
"answer_id": 230572,
"author": "nathan_jr",
"author_id": 3769,
"author_profile": "https://Stackoverflow.com/users/3769",
"pm_score": 1,
"selected": false,
"text": "declare @Item table (ItemId int, ItemDesc varchar(50), Price money)\ndeclare @Invoice table (InvoiceId int, CustomerName varchar(50), ShipDate datetime)\ndeclare @OrderedItem table (InvoiceId int, ItemId int, Quantity int)\n\n\ninsert into @Item\n select 1, 'Hat', '10.99' union\n select 2, 'Shirt', '12.50' union\n select 3, 'Belt', '5.99'\n\ninsert into @Invoice\n select 1, 'Nathan', '01-01-2009'\n\ninsert into @OrderedItem\n select 1, 1, 2 union -- 2 hats\n select 1, 2, 3 -- 3 shirts\n\n\nselect i.InvoiceId,\n sum(Quantity) [TotalItems],\n sum(Price * Quantity) [TotalPrice]\nfrom @Invoice i\ninner\njoin @OrderedItem oi on\n i.InvoiceId = oi.InvoiceId\ninner\njoin @Item it on\n oi.ItemId = it.ItemId\ngroup\nby i.InvoiceId\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
230,584
|
<p>Where are variables in C++ stored?</p>
<p>Inside the RAM or the processor's cache?</p>
|
[
{
"answer_id": 230596,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 1,
"selected": false,
"text": "const"
},
{
"answer_id": 230601,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 3,
"selected": false,
"text": "int x;\n int *p = new int;\n"
},
{
"answer_id": 230613,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 6,
"selected": false,
"text": "static section .data .bss .rodata int *p = new int[10]; p new malloc int auto"
},
{
"answer_id": 230660,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 4,
"selected": false,
"text": "malloc new int a = 10; int * b = &a; b a a"
},
{
"answer_id": 14381449,
"author": "prashanth",
"author_id": 1987470,
"author_profile": "https://Stackoverflow.com/users/1987470",
"pm_score": 1,
"selected": false,
"text": " {\n struct foobar *ptr\n = (struct foobar *) malloc (sizeof (struct foobar));\n ptr->name = x;\n ptr->next = current_foobar;\n current_foobar = ptr;\n }\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
230,585
|
<p>I have the following code:</p>
<pre><code>class IncidentTag:
def __init__(self,tag):
self.tag = tag
def equals(self,obj):
return self.tag.equals(obj.tag)
def hashCode(self):
return self.tag.hashCode()
from java.lang import String
from java.util import HashMap
from java.util import HashSet
tag1 = IncidentTag(String("email"))
tag1copy = IncidentTag(String("email"))
tag2 = IncidentTag(String("notemail"))
print tag1.equals(tag1copy)
print tag2.equals(tag2)
print "Now with HashSet:"
hSet = HashSet()
hSet.add(tag1)
hSet.add(tag2)
print hSet.contains(tag1)
print hSet.contains(tag2)
print hSet.contains(tag1copy)
</code></pre>
<p>The output is:
1
1
Now with HashSet:
1
1
0</p>
<p>However, I would have expected the last line to be <code>true</code>(1) as well. Is there something obvious that I am missing.</p>
<p>(yes, I know that my <code>equals</code> method and <code>hashcode</code> methods do not take some issues into account... they are deliberately simple, but do let me know if the issues there are causing this problem.)</p>
|
[
{
"answer_id": 230812,
"author": "dmeister",
"author_id": 4194,
"author_profile": "https://Stackoverflow.com/users/4194",
"pm_score": 4,
"selected": true,
"text": "__eq__ __hash__ def __hash__(self):\n return self.hashCode()\ndef __eq__(self, o):\n return self.equals(o)\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230585",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1432/"
] |
230,588
|
<p>I am trying to sort a list using delegates but I am getting a signature match error. The compiler says I cannot convert from an 'anonymous method' </p>
<pre><code>List<MyType> myList = GetMyList();
myList.Sort( delegate (MyType t1, MyType t2) { return (t1.ID < t2.ID); } );
</code></pre>
<p>What am I missing?</p>
<p>Here are some references I found and they do it the same way.</p>
<p><a href="http://www.developerfusion.com/code/5513/sorting-and-searching-using-c-lists/" rel="noreferrer">Developer Fusion Reference</a> </p>
<p><a href="http://blogs.msdn.com/devdev/archive/2006/06/30/652802.aspx" rel="noreferrer">Microsoft Reference</a></p>
|
[
{
"answer_id": 230597,
"author": "Jeff Yates",
"author_id": 23234,
"author_profile": "https://Stackoverflow.com/users/23234",
"pm_score": 4,
"selected": false,
"text": "Comparison<T> int bool 0 <0 >0"
},
{
"answer_id": 230620,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 7,
"selected": true,
"text": "myList.Sort( delegate (MyType t1, MyType t2) \n { return (t1.ID.CompareTo(t2.ID)); } \n);\n"
},
{
"answer_id": 230824,
"author": "Coderer",
"author_id": 26286,
"author_profile": "https://Stackoverflow.com/users/26286",
"pm_score": 2,
"selected": false,
"text": "Comparison<MyType> c = delegate(MyType t1, MyType t2){ ... };\nmyList.Sort(c);\n"
},
{
"answer_id": 231197,
"author": "David.Chu.ca",
"author_id": 62776,
"author_profile": "https://Stackoverflow.com/users/62776",
"pm_score": 1,
"selected": false,
"text": "public class MyTypeComparer : IComparer<MyType>\n{\n public MyTypeComparer() // default comparer on ID\n { ... }\n\n public MyTypeComparer(bool desc) // default with order specified\n\n public MyTypeComparer(string sort, bool desc) // specified sort and order such as property name, true or false.\n { ... }\n\n public int Compare(MyType a, MyType b) // implement IComparer interface\n { ... } // this is real sorting codes\n}\n List<MyType> myList = GetList();\nmyList.Sort(new MyTypeComparer());\n// myList.Sort(new MyTypeComparer(false));\n// myList.Sort(new MyTypeComparer(\"FirstName\", true));\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230588",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1632/"
] |
230,592
|
<p>Here's the XML code I'm working with:</p>
<pre><code><inventory>
<drink>
<lemonade supplier="mother" id="1">
<price>$2.50</price>
<amount>20</amount>
</lemonade>
<lemonade supplier="mike" id="4">
<price>$3.00</price>
<amount>20</amount>
</lemonade>
<pop supplier="store" id="2">
<price>$1.50</price>
<amount>10</amount>
</pop>
</drink>
</inventory>
</code></pre>
<p>Then I wrote a simple code to practice working with XPath:</p>
<pre><code><?php
$xmldoc = new DOMDocument();
$xmldoc->load('sample.xml');
$xpathvar = new Domxpath($xmldoc);
$queryResult = $xpathvar->query('//lemonade/price');
foreach($queryResult as $result) {
echo $result->textContent;
}
?>
</code></pre>
<p>That code is working well, outputting all the lemonade price values as expected. Now when i change the query string to select only the elements with an attribute set to a certain value, like </p>
<blockquote>
<p>//lemonade[supplier="mother"]/price</p>
</blockquote>
<p>or </p>
<blockquote>
<p>//lemonade[id="1"]/price</p>
</blockquote>
<p>it won't work, no output at all. What am i doing wrong?</p>
|
[
{
"answer_id": 230609,
"author": "bobwienholt",
"author_id": 24257,
"author_profile": "https://Stackoverflow.com/users/24257",
"pm_score": 6,
"selected": true,
"text": "//lemonade[@id=\"1\"]/price\n //lemonade[@supplier=\"mother\"]/price\n"
},
{
"answer_id": 230619,
"author": "Kris",
"author_id": 18565,
"author_profile": "https://Stackoverflow.com/users/18565",
"pm_score": 3,
"selected": false,
"text": "//lemonade[@supplier=\"mother\"]/price"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230592",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27090/"
] |
230,636
|
<p>I am trying to implement the following functionality:</p>
<pre><code>class WeightResolver {
WeightMonitor _source;
bool _cancelled;
Weight _threshold;
public Cancel() {
_cancelled = true;
}
public Weight Resolve(){
_cancelled = false;
while(_source.CurrentWeight < threshold ) {
if(_cancelled)
throw new CancelledOperationException();
// Wait until one of the above conditions is met
}
return _source.CurrentWeight
}
}
</code></pre>
<p>However I am running into trouble managing my threads. For example, the Cancel method is registered via an event and Resolve invoked as follows:</p>
<pre><code> _activity_timeout_manager.TimeoutHandler += new Action(_weight_resolver.Cancel())l
try {
var weight = _weight_resolver.Resolve();
}
catch(CancelledOperationException) { .... }
</code></pre>
<p>where the activity manager is running a timer on tick of which it invokes events using TimeoutHandler.Invoke();</p>
<p>The problem is that even though it is properly registered with the event, Cancel() never gets called. I believe this is because the thread it is calling to is currently spinning and therefore it never gets a chance at the CPU.</p>
<p>What can I do to remedy the situation short of making the call to Resolve() asynchronous? It is extremely preferable for WeightResolver.Resolve() to stay synchronous because the code calling it should spin unless some return is provided anyways.</p>
<p><strong>EDIT:</strong> To clarify what I'm asking for. This seems like a fairly common set-up and I would be surprised if there isn't a simple standard way to handle it. I simply have never run across the situation before and don't know what exactly it could be.</p>
|
[
{
"answer_id": 230654,
"author": "Karl Seguin",
"author_id": 34,
"author_profile": "https://Stackoverflow.com/users/34",
"pm_score": 1,
"selected": false,
"text": "resolveThread.Start();\nresolveThread.Join(2000); //this will block the main thread, thus making resolve synchronous\nresolveThread.Abort(); //timeout has expired\n"
},
{
"answer_id": 230664,
"author": "bobwienholt",
"author_id": 24257,
"author_profile": "https://Stackoverflow.com/users/24257",
"pm_score": 0,
"selected": false,
"text": "while(_source.CurrentWeight < threshold )\n"
},
{
"answer_id": 230730,
"author": "luke",
"author_id": 25920,
"author_profile": "https://Stackoverflow.com/users/25920",
"pm_score": 0,
"selected": false,
"text": "Condition cond;\nMutex lock;\n\npublic Cancel() {\n lock.lock()\n _cancelled = true;\n cond.signal(lock);\n lock.unlock();\n }\n public Weight Resolve(){\n _cancelled = false;\n lock.lock();\n while(_source.CurrentWeight < threshold) {\n if(_cancelled)\n {\n lock.unlock();\n throw new CancelledOperationException();\n }\n cond.timedWait(lock, 100);\n // Wait until one of the above conditions is met\n }\n lock.unlock();\n return _source.CurrentWeight\n }\n Condition cond;\nMutex lock;\n\npublic Cancel() {\n lock.lock()\n _cancelled = true;\n cond.signal(lock);\n lock.unlock();\n }\n public Weight Resolve(){\n _cancelled = false;\n lock.lock();\n while(_source.CurrentWeight < threshold) {\n if(_cancelled)\n {\n lock.unlock();\n throw new CancelledOperationException();\n }\n cond.wait(lock);\n // Wait until one of the above conditions is met\n }\n lock.unlock();\n return _source.CurrentWeight\n }\n public void updateWeight()\n{\n lock.lock();\n ...update weight;\n cond.signal(lock);\n lock.unlock();\n}\n"
},
{
"answer_id": 230733,
"author": "Brannon",
"author_id": 5745,
"author_profile": "https://Stackoverflow.com/users/5745",
"pm_score": 0,
"selected": false,
"text": "ManualResetEvent bool class WeightResolver {\n WeightMonitor _source;\n ManualResetEvent _cancelled = new ManualResetEvent(false);\n Weight _threshold;\n\n public Cancel() {\n _cancelled.Set();\n }\n public Weight Resolve(){\n _cancelled = false;\n while(_source.CurrentWeight < threshold ) {\n if(_cancelled.WaitOne(100))\n throw new CancelledOperationException();\n // Wait until one of the above conditions is met\n }\n return _source.CurrentWeight\n }\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230636",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5056/"
] |
230,642
|
<p>On our live/production database I'm trying to add a trigger to a table, but have been unsuccessful. I have tried a few times, but it has taken more than 30 minutes for the create trigger statement to complete and I've cancelled it. </p>
<p>The table is one that gets read/written to often by a couple different processes. I have disabled the scheduled jobs that update the table and attempted at times when there is less activity on the table, but I'm not able to stop everything that accesses the table.</p>
<p>I do not believe there is a problem with the create trigger statement itself. The create trigger statement was successful and quick in a test environment, and the trigger works correctly when rows are inserted/updated to the table. Although when I created the trigger on the test database there was no load on the table and it had considerably less rows, which is different than on the live/production database (100 vs. 13,000,000+).</p>
<p>Here is the create trigger statement that I'm trying to run</p>
<pre><code>CREATE TRIGGER [OnItem_Updated]
ON [Item]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
IF update(State)
BEGIN
/* do some stuff including for each row updated call a stored
procedure that increments a value in table based on the
UserId of the updated row */
END
END
</code></pre>
<p>Can there be issues with creating a trigger on a table while rows are being updated or if it has many rows? </p>
<p>In SQLServer triggers are created enabled by default. Is it possible to create the trigger disabled by default? </p>
<p>Any other ideas?</p>
|
[
{
"answer_id": 230719,
"author": "Dave DuPlantis",
"author_id": 8174,
"author_profile": "https://Stackoverflow.com/users/8174",
"pm_score": 2,
"selected": false,
"text": "AFTER UPDATE"
},
{
"answer_id": 37567052,
"author": "Marco Marsala",
"author_id": 2717254,
"author_profile": "https://Stackoverflow.com/users/2717254",
"pm_score": 0,
"selected": false,
"text": "DISABLE TRIGGER triggername ON tablename ENABLE TRIGGER triggername ON tablename"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21353/"
] |
230,643
|
<p>Is there any elegant way in the Android API for detecting new media when it is written to the device? I’m mainly interested in photos taken by the camera, video taken by the camera and audio recorded from the mic.</p>
<p>My current thinking is to periodically scan each media content provider and filter based on last scan time.</p>
<p>I’m just wondering if there is some service I can get realtime notifications.</p>
|
[
{
"answer_id": 236756,
"author": "Reto Meier",
"author_id": 822,
"author_profile": "https://Stackoverflow.com/users/822",
"pm_score": 3,
"selected": false,
"text": "Intent.ACTION_MEDIA_SCANNER_SCAN_FILE\n Intent.getDataString() BroadcastReceiver IntentFilter registerReceiver(new BroadcastReceiver() {\n @Override\n public void onReceive(Context context, Intent intent) {\n String newFileURL = intent.getDataString();\n // TODO React to new Media here. \n } \n }, new IntentFilter(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE));\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230643",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21297/"
] |
230,644
|
<p>I've got a tomcat instance with several apps running on it... I want the root of my new domain to go to one of these apps (context path of blah).. so I have the following set up:</p>
<pre><code><Location />
ProxyPass ajp://localhost:8025/blah
ProxyPassReverse ajp://localhost:8025/blah
</Location>
</code></pre>
<p>it kinda works... going to mydomain.com/index.jsp works except the app still thinks it needs to add the /blah/ to everything like css and js.. is there something I can do without deploying the app to ROOT or changing the tomcat server config? I'd like to keep all this kind of thing on the apache side, if it's possible.</p>
<p>I'm thinking I may not be understanding the proxypassreverse directive.. </p>
|
[
{
"answer_id": 237697,
"author": "f4nt",
"author_id": 14838,
"author_profile": "https://Stackoverflow.com/users/14838",
"pm_score": 3,
"selected": true,
"text": "ProxyPass / ajp://localhost:8025/blah\nProxyPassReverse / ajp://localhost:8025/blah\n"
},
{
"answer_id": 707544,
"author": "Matt Woodward",
"author_id": 3612,
"author_profile": "https://Stackoverflow.com/users/3612",
"pm_score": 0,
"selected": false,
"text": "<Host name=\"myhost\">\n <Context path=\"\" docBase=\"/path/to/files\" />\n</Host>\n <VirtualHost *:80>\n ServerName myhost\n ProxyPass / ajp://myhost:8009/\n ProxyPassReverse / ajp://myhost:8009/\n</VirtualHost>\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2031/"
] |
230,649
|
<h2>Question</h2>
<p>I'm looking for a Java in-memory object caching API. Any recommendations? What solutions have you used in the past?</p>
<h2>Current</h2>
<p>Right now, I'm just using a Map:</p>
<pre><code>Map cache = new HashMap<String, Object>();
cache.put("key", value);
</code></pre>
<h2>Requirements</h2>
<p>I need to extend the cache to include basic features like:</p>
<ul>
<li>Max size</li>
<li>Time to live</li>
</ul>
<p>However, I don't need more sophisticated features like:</p>
<ul>
<li>Access from multiple processes (caching server)</li>
<li>Persistence (to disk)</li>
</ul>
<h2>Suggestions</h2>
<p>In-Memory caching:</p>
<ul>
<li><a href="http://guava-libraries.googlecode.com" rel="noreferrer">Guava</a> CacheBuilder - active development. See this <a href="https://github.com/liubo404/it-ebooks/blob/master/pdf/JavaCachingwithGuava.pdf" rel="noreferrer">presentation</a>.</li>
<li><a href="http://commons.apache.org/collections/apidocs/org/apache/commons/collections/map/LRUMap.html" rel="noreferrer">LRUMap</a> - Config via API. No TTL. Not purpose built for caching.</li>
<li><a href="http://whirlycache.dev.java.net/" rel="noreferrer">whirlycache</a> - XML config. Mailing list. Last updated 2006.</li>
<li><a href="http://cache4j.sourceforge.net/" rel="noreferrer">cache4j</a> - XML config. Documentation in Russian. Last updated 2006.</li>
</ul>
<p>Enterprise caching:</p>
<ul>
<li><a href="http://jakarta.apache.org/jcs" rel="noreferrer">JCS</a> - Properties config. Extensive documentation.</li>
<li><a href="http://ehcache.sourceforge.net" rel="noreferrer">Ehcache</a> - XML config. Extensive documentation. By far the most popular according to Google hits.</li>
</ul>
|
[
{
"answer_id": 230659,
"author": "Steve K",
"author_id": 739,
"author_profile": "https://Stackoverflow.com/users/739",
"pm_score": 7,
"selected": true,
"text": "CacheManager cacheManager = CacheManager.getInstance();\nint oneDay = 24 * 60 * 60;\nCache memoryOnlyCache = new Cache(\"name\", 200, false, false, oneDay, oneDay);\ncacheManager.addCache(memoryOnlyCache);\n"
},
{
"answer_id": 230727,
"author": "JeeBee",
"author_id": 17832,
"author_profile": "https://Stackoverflow.com/users/17832",
"pm_score": 3,
"selected": false,
"text": " Map <String, Foo> cache = new LinkedHashMap<String, Foo>(MAX_ENTRIES + 1, .75F, true) {\n\n public boolean removeEldestEntry(Map.Entry<String, Foo> eldest) {\n return size() > MAX_ENTRIES;\n }\n };\n Foo foo = cache.get(key);\n if (foo == null && !cache.containsKey(key)) {\n try {\n FooDAO fooDAO = DAOFactory.getFooDAO(conn);\n foo = fooDAO.getFooByKey(key);\n cache.put(key, foo);\n } catch (SQLException sqle) {\n logger.error(\"[getFoo] SQL Exception when accessing Foo\", sqle);\n }\n }\n"
},
{
"answer_id": 1367663,
"author": "Joachim Sauer",
"author_id": 40342,
"author_profile": "https://Stackoverflow.com/users/40342",
"pm_score": 6,
"selected": false,
"text": "MapMaker ConcurrentMap<Key, Graph> graphs = new MapMaker()\n .concurrencyLevel(32)\n .softKeys()\n .weakValues()\n .expiration(30, TimeUnit.MINUTES)\n .makeComputingMap(\n new Function<Key, Graph>() {\n public Graph apply(Key key) {\n return createExpensiveGraph(key);\n }\n });\n com.google.common.cache"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7679/"
] |
230,662
|
<p>I have a table that has a column with a default value:</p>
<pre><code>create table t (
value varchar(50) default ('something')
)
</code></pre>
<p>I'm using a stored procedure to insert values into this table:</p>
<pre><code>create procedure t_insert (
@value varchar(50) = null
)
as
insert into t (value) values (@value)
</code></pre>
<p>The question is, how do I get it to use the default when <code>@value</code> is <code>null</code>? I tried:</p>
<pre><code>insert into t (value) values ( isnull(@value, default) )
</code></pre>
<p>That obviously didn't work. Also tried a <code>case</code> statement, but that didn't fair well either. Any other suggestions? Am I going about this the wrong way?</p>
<p>Update: I'm trying to accomplish this <strong>without</strong> having to:</p>
<ol>
<li>maintain the <code>default</code> value in multiple places, and</li>
<li>use multiple <code>insert</code> statements.</li>
</ol>
<p>If this isn't possible, well I guess I'll just have to live with it. It just seems that something this should be attainable.</p>
<p>Note: my actual table has more than one column. I was just quickly writing an example.</p>
|
[
{
"answer_id": 230676,
"author": "Brian Hasden",
"author_id": 28926,
"author_profile": "https://Stackoverflow.com/users/28926",
"pm_score": 2,
"selected": false,
"text": "INSERT INTO t (value1, value3) VALUES ('value1', 'value3')\n"
},
{
"answer_id": 230678,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 1,
"selected": false,
"text": "CREATE PROCEDURE MyTestProcedure ( @MyParam1 INT,\n@MyParam2 VARCHAR(20) = ‘ABC’,\n@MyParam3 INT = NULL)\nAS\nBEGIN\n -- Procedure body here\n\nEND\n"
},
{
"answer_id": 230717,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": -1,
"selected": false,
"text": "CREATE TABLE Demo\n(\n MyColumn VARCHAR(10) NOT NULL DEFAULT 'Me'\n)\n CREATE PROCEDURE InsertDemo\n @MyColumn VARCHAR(10) = null\nAS\nINSERT INTO Demo (MyColumn) VALUES(@MyColumn)\n"
},
{
"answer_id": 230771,
"author": "Dave DuPlantis",
"author_id": 8174,
"author_profile": "https://Stackoverflow.com/users/8174",
"pm_score": 4,
"selected": false,
"text": "if @value is null \n insert into t (value) values (default)\nelse\n insert into t (value) values (@value)\n"
},
{
"answer_id": 230902,
"author": "Eoin Campbell",
"author_id": 30155,
"author_profile": "https://Stackoverflow.com/users/30155",
"pm_score": 4,
"selected": false,
"text": "CREATE TABLE myTable (\n always VARCHAR(50),\n value1 VARCHAR(50) DEFAULT ('defaultcol1'),\n value2 VARCHAR(50) DEFAULT ('defaultcol2'),\n value3 VARCHAR(50) DEFAULT ('defaultcol3')\n)\n ALTER PROCEDURE t_insert (\n @always VARCHAR(50),\n @value1 VARCHAR(50) = NULL,\n @value2 VARCHAR(50) = NULL,\n @value3 VARCAHR(50) = NULL\n)\nAS \nBEGIN\nDECLARE @insertpart VARCHAR(500)\nDECLARE @valuepart VARCHAR(500)\n\nSET @insertpart = 'INSERT INTO myTable ('\nSET @valuepart = 'VALUES ('\n\n IF @value1 IS NOT NULL\n BEGIN\n SET @insertpart = @insertpart + 'value1,'\n SET @valuepart = @valuepart + '''' + @value1 + ''', '\n END\n\n IF @value2 IS NOT NULL\n BEGIN\n SET @insertpart = @insertpart + 'value2,'\n SET @valuepart = @valuepart + '''' + @value2 + ''', '\n END\n\n IF @value3 IS NOT NULL\n BEGIN\n SET @insertpart = @insertpart + 'value3,'\n SET @valuepart = @valuepart + '''' + @value3 + ''', '\n END\n\n SET @insertpart = @insertpart + 'always) '\n SET @valuepart = @valuepart + + '''' + @always + ''')'\n\n--print @insertpart + @valuepart\nEXEC (@insertpart + @valuepart)\nEND\n EXEC t_insert 'alwaysvalue'\nSELECT * FROM myTable\n\nEXEC t_insert 'alwaysvalue', 'val1'\nSELECT * FROM myTable\n\nEXEC t_insert 'alwaysvalue', 'val1', 'val2', 'val3'\nSELECT * FROM myTable\n"
},
{
"answer_id": 231822,
"author": "Lurker Indeed",
"author_id": 16951,
"author_profile": "https://Stackoverflow.com/users/16951",
"pm_score": 2,
"selected": false,
"text": " CREATE FUNCTION GetDefaultValue\n (\n @TableName VARCHAR(200),\n @ColumnName VARCHAR(200)\n )\n RETURNS VARCHAR(200)\n AS\n BEGIN\n -- you'd probably want to have different functions for different data types if\n -- you go this route\n RETURN (SELECT TOP 1 REPLACE(REPLACE(REPLACE(COLUMN_DEFAULT, '(', ''), ')', ''), '''', '') \n FROM information_schema.columns\n WHERE table_name = @TableName AND column_name = @ColumnName)\n\n END\n GO\n INSERT INTO t (value) VALUES ( ISNULL(@value, SELECT dbo.GetDefaultValue('t', 'value') )\n"
},
{
"answer_id": 9361365,
"author": "sihirbazzz",
"author_id": 967770,
"author_profile": "https://Stackoverflow.com/users/967770",
"pm_score": 0,
"selected": false,
"text": "`USE [YourTable]\nGO\n\n\nSET ANSI_NULLS ON\nGO\n\nSET QUOTED_IDENTIFIER ON\nGO\n\nCREATE PROC [dbo].[YourTableName]\n\n @Value smallint,\n @Value1 bigint,\n @Value2 varchar(50),\n @Value3 varchar(20),\n @Value4 varchar(20),\n @Value5 date,\n @Value6 varchar(50),\n @Value7 tinyint,\n @Value8 tinyint,\n @Value9 varchar(20),\n @Value10 varchar(20),\n @Value11 varchar(250),\n @Value12 tinyint,\n @Value13 varbinary(max) \n AS\n--SET NOCOUNT ON\nIF @Value = 0 BEGIN\n INSERT INTO YourTableName (\n [TableColumn1],\n [TableColumn2],\n [TableColumn3],\n [TableColumn4],\n [TableColumn5],\n [TableColumn6],\n [TableColumn7],\n [TableColumn8],\n [TableColumn9],\n [TableColumn10],\n [TableColumn11],\n [TableColumn12],\n [TableColumn13]\n )\n VALUES (\n @Value1,\n @Value2,\n @Value3,\n @Value4,\n @Value5,\n @Value6,\n @Value7,\n @Value8,\n @Value9,\n @Value10,\n @Value11,\n @Value12,\n default\n )\n SELECT SCOPE_IDENTITY() As InsertedID\nEND\nELSE BEGIN\n UPDATE YourTableName SET \n [TableColumn1] = @Value1,\n [TableColumn2] = @Value2,\n [TableColumn3] = @Value3,\n [TableColumn4] = @Value4,\n [TableColumn5] = @Value5,\n [TableColumn6] = @Value6,\n [TableColumn7] = @Value7,\n [TableColumn8] = @Value8,\n [TableColumn9] = @Value9,\n [TableColumn10] = @Value10,\n [TableColumn11] = @Value11,\n [TableColumn12] = @Value12,\n [TableColumn13] = @Value13\n WHERE [TableColumn] = @Value\n\nEND\nGO`\n"
},
{
"answer_id": 10322923,
"author": "sqlserverguy",
"author_id": 1357127,
"author_profile": "https://Stackoverflow.com/users/1357127",
"pm_score": 2,
"selected": false,
"text": "CREATE PROCEDURE t_insert ( @value varchar(50) = null )\nas\nDECLARE @sQuery NVARCHAR (MAX);\nSET @sQuery = N'\ninsert into __t (value) values ( '+\nCASE WHEN @value IS NULL THEN ' default ' ELSE ' @value ' END +' );';\n\nEXEC sp_executesql \n@stmt = @sQuery, \n@params = N'@value varchar(50)',\n@value = @value;\n\nGO\n"
},
{
"answer_id": 10831236,
"author": "Jonathan",
"author_id": 6910,
"author_profile": "https://Stackoverflow.com/users/6910",
"pm_score": 0,
"selected": false,
"text": "INSERT t DEFAULT VALUES\n"
},
{
"answer_id": 25590863,
"author": "Nicolás Orlando",
"author_id": 3994419,
"author_profile": "https://Stackoverflow.com/users/3994419",
"pm_score": 2,
"selected": false,
"text": "CREATE TABLE t (\n insValue VARCHAR(50) NULL\n , selValue AS ISNULL(insValue, 'something')\n)\n\nDECLARE @d VARCHAR(10)\nINSERT INTO t (insValue) VALUES (@d) -- null\nSELECT selValue FROM t\n selValue AS ISNULL(insValue, 'something')\n selValue AS ISNULL(insValue, **getDef(t,1)**)\n"
},
{
"answer_id": 35613752,
"author": "Roy Fulbright",
"author_id": 975435,
"author_profile": "https://Stackoverflow.com/users/975435",
"pm_score": -1,
"selected": false,
"text": "IF OBJECT_ID('tempdb..#mytest') IS NOT NULL DROP TABLE #mytest\nCREATE TABLE #mytest(f1 INT DEFAULT(1), f2 INT)\nINSERT INTO #mytest(f1,f2) VALUES (NULL,2)\nINSERT INTO #mytest(f1,f2) VALUES (3,3)\n\nUPDATE #mytest SET f1 = DEFAULT WHERE f1 IS NULL\n\nSELECT * FROM #mytest\n"
},
{
"answer_id": 43410866,
"author": "Blade",
"author_id": 3384036,
"author_profile": "https://Stackoverflow.com/users/3384036",
"pm_score": 2,
"selected": false,
"text": "create trigger dbo.OnInsertIntoT\nON TablenameT\nINSTEAD OF INSERT\nAS\ninsert into TablenameT\nselect\n IsNull(column1 ,<default_value>)\n ,IsNull(column2 ,<default_value>)\n ...\nfrom inserted\n"
},
{
"answer_id": 52522020,
"author": "Allinuon",
"author_id": 10419896,
"author_profile": "https://Stackoverflow.com/users/10419896",
"pm_score": -1,
"selected": false,
"text": "-- create initial row with default values\ninsert table1 (col1, col2, col3)\n values (@col1, @col2, @col3)\n\n-- update default values, if supplied\nupdate table1\n set col4 = isnull(@col4, col4),\n col5 = isnull(@col5, col5)\n where col1 = @col1\n -- create initial row with default values\ninsert table1 (col1, col2, col3)\n values (@col1, @col2, @col3)\n\n-- create a container to hold the values actually inserted into the table\ndeclare @inserted table (col4 datetime, col5 varchar(50))\n\n-- update default values, if supplied\nupdate table1\n set col4 = isnull(@col4, col4),\n col5 = isnull(@col5, col5)\n output inserted.col4, inserted.col5 into @inserted (col4, col5)\n where col1 = @col1\n\n-- get the values defaulted into the table (optional)\nselect @col4 = col4, @col5 = col5 from @inserted\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230662",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2614/"
] |
230,687
|
<p>PHP has a very nice function, isset($variableName). It checks if $variableName is already defined in the program or not.</p>
<p>Can we build similar feature for C/C++ (some kind of symbol table lookup)?</p>
|
[
{
"answer_id": 230729,
"author": "Jeffrey Martinez",
"author_id": 29703,
"author_profile": "https://Stackoverflow.com/users/29703",
"pm_score": 5,
"selected": true,
"text": "// code code code\n#ifdef DEBUG\n// debug only code that will not be included in final product.\n#endif\n// more code more code\n"
},
{
"answer_id": 230816,
"author": "Jon Trauntvein",
"author_id": 19674,
"author_profile": "https://Stackoverflow.com/users/19674",
"pm_score": 3,
"selected": false,
"text": "typedef std::map<std::string, int> variables_type;\nvariables_type variables;\n\nvariables[\"var\"] = 1;\nif(variables.find(\"jon\") == variables.end())\n std::cout << \"variable, \\\"jon\\\" not set\\n\";\n"
},
{
"answer_id": 231071,
"author": "Paul de Vrieze",
"author_id": 4100,
"author_profile": "https://Stackoverflow.com/users/4100",
"pm_score": 1,
"selected": false,
"text": "int * x(getFoo());\nif (x) {\n cout << \"Foo has a result.\" << endl;\n} else {\n cout << \"Foo returns null.\" << endl;\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6561/"
] |
230,689
|
<p>I'd like a consistent and simple way to throw exceptions in JNI code; something that handles chained exceptions (implicitly from the env->ExceptionOccurred method, or explicitly by parameters, either way is good) and saves me looking up constructors every time I want to do this. All of the above is preferably in C, although I could translate it from C++ at need.</p>
<p>Does anyone on SO have something like this that they can share?</p>
|
[
{
"answer_id": 240506,
"author": "Steven M. Cherry",
"author_id": 24193,
"author_profile": "https://Stackoverflow.com/users/24193",
"pm_score": 7,
"selected": true,
"text": "jint throwNoClassDefError( JNIEnv *env, char *message )\n{\n jclass exClass;\n char *className = \"java/lang/NoClassDefFoundError\";\n\n exClass = (*env)->FindClass( env, className);\n if (exClass == NULL) {\n return throwNoClassDefError( env, className );\n }\n\n return (*env)->ThrowNew( env, exClass, message );\n}\n\njint throwNoSuchMethodError(\n JNIEnv *env, char *className, char *methodName, char *signature )\n{\n\n jclass exClass;\n char *exClassName = \"java/lang/NoSuchMethodError\" ;\n LPTSTR msgBuf;\n jint retCode;\n size_t nMallocSize;\n\n exClass = (*env)->FindClass( env, exClassName );\n if ( exClass == NULL ) {\n return throwNoClassDefError( env, exClassName );\n }\n\n nMallocSize = strlen(className) \n + strlen(methodName)\n + strlen(signature) + 8;\n\n msgBuf = malloc( nMallocSize );\n if ( msgBuf == NULL ) {\n return throwOutOfMemoryError\n ( env, \"throwNoSuchMethodError: allocating msgBuf\" );\n }\n memset( msgBuf, 0, nMallocSize );\n\n strcpy( msgBuf, className );\n strcat( msgBuf, \".\" );\n strcat( msgBuf, methodName );\n strcat( msgBuf, \".\" );\n strcat( msgBuf, signature );\n\n retCode = (*env)->ThrowNew( env, exClass, msgBuf );\n free ( msgBuf );\n return retCode;\n}\n\njint throwNoSuchFieldError( JNIEnv *env, char *message )\n{\n jclass exClass;\n char *className = \"java/lang/NoSuchFieldError\" ;\n\n exClass = (*env)->FindClass( env, className );\n if ( exClass == NULL ) {\n return throwNoClassDefError( env, className );\n }\n\n return (*env)->ThrowNew( env, exClass, message );\n}\n\njint throwOutOfMemoryError( JNIEnv *env, char *message )\n{\n jclass exClass;\n char *className = \"java/lang/OutOfMemoryError\" ;\n\n exClass = (*env)->FindClass( env, className );\n if ( exClass == NULL ) {\n return throwNoClassDefError( env, className );\n }\n\n return (*env)->ThrowNew( env, exClass, message );\n}\n"
},
{
"answer_id": 9812796,
"author": "Java42",
"author_id": 1250303,
"author_profile": "https://Stackoverflow.com/users/1250303",
"pm_score": 5,
"selected": false,
"text": " sprintf(exBuffer, \"NE%4.4X: Caller can %s %s print\", marker, \"log\", \"or\");\n (*env)->ThrowNew(env, (*env)->FindClass(env, \"java/lang/Exception\"), exBuffer);\n Exception in thread \"main\" java.lang.Exception: NE0042: Caller can log or print.\n"
},
{
"answer_id": 12215825,
"author": "android.weasel",
"author_id": 444234,
"author_profile": "https://Stackoverflow.com/users/444234",
"pm_score": 3,
"selected": false,
"text": "JNIEXPORT void JNICALL Java_com_pany_jni_JNIClass_something(JNIEnv* env, jobject self)\n{\n try\n {\n ... do JNI stuff\n // return something; if not void.\n }\n catch (PendingException e) // (Should be &e perhaps?)\n {\n /* any necessary clean-up */\n }\n}\n class PendingException {};\n PendingException PENDING_JNI_EXCEPTION;\nvoid throwIfPendingException(JNIEnv* env)\n{\n if (env->ExceptionCheck()) {\n throw PENDING_JNI_EXCEPTION;\n }\n}\n java.lang.NoSuchFieldError: no field with name='opaque' signature='J' in class Lcom/pany/jni/JniClass;\n at com.pany.jni.JniClass.construct(Native Method)\n at com.pany.jni.JniClass.doThing(JniClass.java:169)\n at com.pany.jni.JniClass.access$1(JniClass.java:151)\n at com.pany.jni.JniClass$2.onClick(JniClass.java:129)\n at android.view.View.performClick(View.java:4084)\n java.lang.RuntimeException: YouSuck\n at com.pany.jni.JniClass.fail(JniClass.java:35)\n at com.pany.jni.JniClass.getVersion(Native Method)\n at com.pany.jni.JniClass.doThing(JniClass.java:172)\n void impendNewJniException(JNIEnv* env, const char *classNameNotSignature, const char *message)\n{\n jclass jClass = env->FindClass(classNameNotSignature);\n throwIfPendingException(env);\n env->ThrowNew(jClass, message);\n}\n\nvoid throwNewJniException(JNIEnv* env, const char* classNameNotSignature, const char* message)\n{\n impendNewJniException(env, classNameNotSignature, message);\n throwIfPendingException(env);\n}\n"
},
{
"answer_id": 53961548,
"author": "Canato",
"author_id": 3117650,
"author_profile": "https://Stackoverflow.com/users/3117650",
"pm_score": 2,
"selected": false,
"text": "Throw Exception public native int func(Param1, Param2, Param3) throws IOException;\n IOException Exception JNIEXPORT int JNICALL Java_YourClass_func\n(int Param1, int Param2, int Param3) {\n if (Param3 == 0) { //something wrong\n jclass Exception = env->FindClass(\"java/lang/Exception\");\n env->ThrowNew(Exception, \"Can't divide by zero.\"); // Error Message\n }\n return (Param1+Param2)/Param3;\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23309/"
] |
230,702
|
<p>I need a tool to execute XSLTs against <strong>very large</strong> XML files. To be clear, I don't need anything to design, edit, or debug the XSLTs, just execute them. The transforms that I am using are already well optimized, but the large files are causing the tool I have tried (Saxon v9.1) to run out of memory.</p>
|
[
{
"answer_id": 241717,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "XmlReader"
},
{
"answer_id": 5881234,
"author": "Vitaliy Ulantikov",
"author_id": 63867,
"author_profile": "https://Stackoverflow.com/users/63867",
"pm_score": 0,
"selected": false,
"text": "XPathDocument srcDoc = new XPathDocument(srcFile);\nXslCompiledTransform myXslTransform = new XslCompiledTransform();\nmyXslTransform.Load(xslFile);\nusing (XmlWriter destDoc = XmlWriter.Create(destFile))\n{\n myXslTransform.Transform(srcDoc, destDoc);\n}\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4593/"
] |
230,706
|
<h3>Question</h3>
<p>My question is how can you teach the methods and importance of tidying-up and refactoring code?</p>
<h3>Background</h3>
<p>I was recently working on a code review for a colleague. They had made some modifications to a long-gone colleagues work. During the new changes, my colleague had tried to refactor items but gave up as soon as they hit a crash or some other problem (rather than chasing the rabbit down the hole to find the root of the issue) and so reimplemented the problem code and built more on top of that. This left the code in a tangle of workarounds and magic numbers, so I sat down with them to go through refactoring it.</p>
<p>I tried to explain how I was identifying the places we could refactor and how each refactoring can often highlight new areas. For example, there were two variables that stored the same information - why? I guessed it was a workaround for a bigger issue so I took out one variable and chased the rabbit down the hole, discovering other problems as we went. This eventually led to finding a problem where we were looping over the same things several times. This was due in no small part to the use of arrays of magic number sizes that obfuscated what was being done - fixing the initial "double-variable" problem led to this discovery (and others).</p>
<p>As I went on this refactoring journey with my colleague, it was evident that she wasn't always able to grasp why we made certain changes and how we could be sure the new functionality matched the original, so I took the time to explain and prove each change by comparing with earlier versions and stepping through the changes on paper. I also explained, through examples, how to tell if a refactoring choice was a bad idea, when to choose comments instead of code changes, and how to select good variable names.</p>
<p>I felt that the process of sitting together to do this was worthwhile for both myself (I got to learn a bit more about how best to explain things to others) and my colleague (they got to understand more of our code and our coding practices) but, the experience led me to wonder if there was a better way to teach the refactoring process.</p>
<h3>...and finally...</h3>
<p>I understand that what does or does not need refactoring, and how to refactor it are very subjective so I want to steer clear of that discussion, but I am interested to learn how others would tackle the challenge of teaching this important skill, and if others here have had similar experiences and what they learned from them (either as the teacher or the student).</p>
|
[
{
"answer_id": 230799,
"author": "dirtside",
"author_id": 20903,
"author_profile": "https://Stackoverflow.com/users/20903",
"pm_score": 1,
"selected": false,
"text": "xy + xz\n x(y + z)\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230706",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23234/"
] |
230,715
|
<p>Alright, after doing a ton of research and trying almost every managed CPP Redist I can find as well as trying to copy my DLLs locally to the executing directory of the app I cannot figure out what dependencies i'm missing for this mixed mode library.</p>
<p>Basically I have a large C# application and I'm trying to use a mixed mode library I made. On the development machine it works perfect (of course) but deployed when the library needs to be loaded for use it exceptions out because of missing CRT dependencies (I assume).</p>
<p>I have used dependency walker to check all the DLLs referenced and ensured they exist on the deployment machine with no luck, I'm wondering if maybe it's some dependencies that need to be registered that I am missing, but i can't figure out what.</p>
<p>I get the following exception when code tries to instantiate a class from the mixed mode library.</p>
<blockquote>
<p>Exception Detail:
System.IO.FileLoadException: Could not
load file or assembly 'USADSI.MAPI,
Version=1.0.3174.25238,
Culture=neutral, PublicKeyToken=null'
or one of its dependencies. This
application has failed to start
because the application configuration
is incorrect. Reinstalling the
application may fix this problem.
(Exception from HRESULT: 0x800736B1)</p>
</blockquote>
<p>I am compiling the library using VS2008 SP1 with /clr:oldSyntax specified.</p>
<p>The intermediate manifest looks like this:</p>
<pre><code><assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
</assembly>
</code></pre>
<p>I can provide any more information as needed, unfortunately i'm not well versed in making mixed mode libraries so this has thrown me off.</p>
<p>If anyone can offer any advice I would greatly appreciate it!</p>
|
[
{
"answer_id": 938375,
"author": "RandomNickName42",
"author_id": 67819,
"author_profile": "https://Stackoverflow.com/users/67819",
"pm_score": 2,
"selected": false,
"text": "#pragma comment(linker, \\\n \"\\\"/manifestdependency:type='Win32' \"\\\n \"name='Microsoft.Windows.Common-Controls' \"\\\n \"version='6.0.0.0' \"\\\n \"processorArchitecture='*' \"\\\n \"publicKeyToken='6595b64144ccf1df' \"\\\n \"language='*'\\\"\")\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230715",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12707/"
] |
230,716
|
<p>I'm using C# & .NEt 3.5. What is the difference between the OptionA and OptionB ?</p>
<pre><code>class MyClass
{
private object m_Locker = new object();
private Dicionary<string, object> m_Hash = new Dictionary<string, object>();
public void OptionA()
{
lock(m_Locker){
// Do something with the dictionary
}
}
public void OptionB()
{
lock(m_Hash){
// Do something with the dictionary
}
}
}
</code></pre>
<p>I'm starting to dabble in threading (primarly for creating a cache for a multi-threaded app, NOT using the HttpCache class, since it's not attached to a web site), and I see the OptionA syntax in a lot of the examples I see online, but I don't understand what, if any, reason that is done over OptionB.</p>
|
[
{
"answer_id": 230753,
"author": "Corbin March",
"author_id": 7625,
"author_profile": "https://Stackoverflow.com/users/7625",
"pm_score": 6,
"selected": true,
"text": "lock (m_Hash)\n{\n // Across all threads, I can be in one and only one of these two blocks\n // Do something with the dictionary\n}\nlock (m_Hash)\n{\n // Across all threads, I can be in one and only one of these two blocks\n // Do something with the dictionary\n}\n private object m_LockerA = new object();\nprivate object m_LockerB = new object();\n\nlock (m_LockerA)\n{\n // It's possible this block is active in one thread\n // while the block below is active in another\n // Do something with the dictionary\n}\nlock (m_LockerB)\n{\n // It's possible this block is active in one thread\n // while the block above is active in another\n // Do something with the dictionary\n}\n"
},
{
"answer_id": 230766,
"author": "faulty",
"author_id": 20007,
"author_profile": "https://Stackoverflow.com/users/20007",
"pm_score": 1,
"selected": false,
"text": "lock(this)"
},
{
"answer_id": 230784,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 0,
"selected": false,
"text": "ICollection.SyncRoot"
},
{
"answer_id": 8922406,
"author": "D.P.",
"author_id": 1063480,
"author_profile": "https://Stackoverflow.com/users/1063480",
"pm_score": 3,
"selected": false,
"text": "lock(this)"
},
{
"answer_id": 33261655,
"author": "John Demetriou",
"author_id": 1766548,
"author_profile": "https://Stackoverflow.com/users/1766548",
"pm_score": 0,
"selected": false,
"text": "lock(this)"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230716",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17803/"
] |
230,718
|
<p>I was wondering if there's a way to see the output of any command,
straight inside vim, rather than first redirecting it into a file and
then opening that file.</p>
<p>E.x. I need something like
$ gvim < <code>diff -r dir1/ dir2/</code></p>
<p>This gives ambiguous redirect error message</p>
<p>I just want to see the diffs between dir1 and dir2 straight inside
gvim.</p>
<p>Can any one provide a nice hack?</p>
|
[
{
"answer_id": 230739,
"author": "jvasak",
"author_id": 5840,
"author_profile": "https://Stackoverflow.com/users/5840",
"pm_score": 5,
"selected": false,
"text": "diff file1 file2 | vim -R -\n -R vim"
},
{
"answer_id": 230794,
"author": "Peter Stone",
"author_id": 1806,
"author_profile": "https://Stackoverflow.com/users/1806",
"pm_score": 3,
"selected": false,
"text": "vim -d file1 file2"
},
{
"answer_id": 230941,
"author": "skinp",
"author_id": 2907,
"author_profile": "https://Stackoverflow.com/users/2907",
"pm_score": 3,
"selected": false,
"text": ":r! diff file1 file2\n"
},
{
"answer_id": 231118,
"author": "Walter",
"author_id": 23840,
"author_profile": "https://Stackoverflow.com/users/23840",
"pm_score": 3,
"selected": false,
"text": "vimdiff vim -d moreutils xargs rm"
},
{
"answer_id": 941629,
"author": "Nathan Fellman",
"author_id": 1084,
"author_profile": "https://Stackoverflow.com/users/1084",
"pm_score": 2,
"selected": false,
"text": "diff -r dir1/ dir2/ | gvim -\n -"
},
{
"answer_id": 7132868,
"author": "ajwood",
"author_id": 512652,
"author_profile": "https://Stackoverflow.com/users/512652",
"pm_score": 1,
"selected": false,
"text": "vimdiff -g <file1> <file2>"
},
{
"answer_id": 13970626,
"author": "VineetChirania",
"author_id": 1746474,
"author_profile": "https://Stackoverflow.com/users/1746474",
"pm_score": 0,
"selected": false,
"text": "vimdiff -R <file1> <file2>\n"
},
{
"answer_id": 25632528,
"author": "drrossum",
"author_id": 839485,
"author_profile": "https://Stackoverflow.com/users/839485",
"pm_score": 0,
"selected": false,
"text": "vim <(diff -r dir1/ dir2/)"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230718",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
230,724
|
<p>I'm using a small site to experiment with the uploading of pictures and displaying them.</p>
<p>When someone clicks "add a picture", they get taken to a page with a form on it. They can select a file and click the submit button.</p>
<p>But what I want to do now is this: put a second submit button labeled "Cancel" next to the normal confirmation button. If someone then chooses to upload, selects and hits submit, if they press the cancel button before the file is fully uploaded, PHP should stop the uploading of the file and delete it. And then just go back to the overview.</p>
<p>No Javascript used whatsoever.</p>
<p>I only have localhost, so testing this in kindof impossible, since I just copy a file the millisecond I press the submit button. There's no upload-time with a localhost and I'm not going to buy a server somewhere just for this.</p>
<p>Basically what's happening now is that the PHP detects which button was sent. If the submit button was sent, the file is uploaded, if the cancel button is sent, it just goes back to the overview.</p>
<p>But PHP does its tasks one in a row. So I don't think this will work. How do I tell PHP to stop doing the upload?</p>
|
[
{
"answer_id": 230748,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 4,
"selected": true,
"text": "<form> <form> <input type=\"file> <input type=\"submit\" value=\"upload\"> </form>\n<form> <input type=\"submit\" value=\"cancel\"> </form>\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11795/"
] |
230,736
|
<p>Is it possible for a generic interface's type to be based on a specific parent class?</p>
<p>For example:</p>
<pre><code>public interface IGenericFace<T : BaseClass>
{
}
</code></pre>
<p>Obviously the above code doesn't work but if it did, what I'm trying to tell the compiler is that <code>T</code> must be a sub-class of <code>BaseClass</code>. Can that be done, are there plans for it, etc.?</p>
<p>I think it would be useful in terms of a specific project, making sure a generic interface/class isn't used with unintended type(s) at compile time. Or also to sort of self-document: show what kind of type is intended.</p>
|
[
{
"answer_id": 230742,
"author": "Ryan Lundy",
"author_id": 5486,
"author_profile": "https://Stackoverflow.com/users/5486",
"pm_score": 8,
"selected": true,
"text": "public interface IGenericFace<T> where T : SomeBaseClass\n"
},
{
"answer_id": 230749,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "public interface IGenericFace<T>\n where T : BaseClass\n{\n}\n"
},
{
"answer_id": 230805,
"author": "Micah",
"author_id": 17744,
"author_profile": "https://Stackoverflow.com/users/17744",
"pm_score": 6,
"selected": false,
"text": "where T: struct Nullable where T : class where T : new() new() where T : <base class name> where T : <interface name> where T : U T U public class TestClass<T> where T : MyBaseClass, INotifyPropertyChanged, new() { }\npublic interface IGenericFace<T> where T : SomeBaseClass\n Public Class TestClass(Of T As {MyBaseClass, INotifyPropertyChanged, New})\nPublic Interface IGenericInterface(Of T As SomeBaseClass)\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230736",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9642/"
] |
230,751
|
<p>How do I force Python's <code>print</code> function to flush the buffered output to the screen?</p>
|
[
{
"answer_id": 230774,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 12,
"selected": true,
"text": "print flush print(\"Hello, World!\", flush=True)\n print import sys\nsys.stdout.flush()\n print sys.stdout"
},
{
"answer_id": 230780,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 9,
"selected": false,
"text": "python -h"
},
{
"answer_id": 231216,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 5,
"selected": false,
"text": "-u -u stdout class flushfile:\n def __init__(self, f):\n self.f = f\n\n def write(self, x):\n self.f.write(x)\n self.f.flush()\n\nimport sys\nsys.stdout = flushfile(sys.stdout)\n print sys.stdout flush"
},
{
"answer_id": 288536,
"author": "Kamil Kisiel",
"author_id": 15061,
"author_profile": "https://Stackoverflow.com/users/15061",
"pm_score": 4,
"selected": false,
"text": "#!/usr/bin/env python\nclass flushfile(file):\n def __init__(self, f):\n self.f = f\n def write(self, x):\n self.f.write(x)\n self.f.flush()\n\nimport sys\nsys.stdout = flushfile(sys.stdout)\n\nprint \"foo\"\n Traceback (most recent call last):\n File \"./passpersist.py\", line 12, in <module>\n print \"foo\"\nValueError: I/O operation on closed file\n class flushfile(file):\n class flushfile(object):\n"
},
{
"answer_id": 741601,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "f = open('xyz.log', 'a', 0)\n sys.stdout = open('out.log', 'a', 0)\n"
},
{
"answer_id": 6055744,
"author": "guettli",
"author_id": 633961,
"author_profile": "https://Stackoverflow.com/users/633961",
"pm_score": 4,
"selected": false,
"text": "class FlushFile(object):\n def __init__(self, fd):\n self.fd = fd\n\n def write(self, x):\n ret = self.fd.write(x)\n self.fd.flush()\n return ret\n\n def writelines(self, lines):\n ret = self.writelines(lines)\n self.fd.flush()\n return ret\n\n def flush(self):\n return self.fd.flush\n\n def close(self):\n return self.fd.close()\n\n def fileno(self):\n return self.fd.fileno()\n"
},
{
"answer_id": 9462099,
"author": "Antony Hatchkins",
"author_id": 237105,
"author_profile": "https://Stackoverflow.com/users/237105",
"pm_score": 6,
"selected": false,
"text": "sys.stdout sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)\n stdout.write print"
},
{
"answer_id": 23142556,
"author": "Eugene Sajine",
"author_id": 673423,
"author_profile": "https://Stackoverflow.com/users/673423",
"pm_score": 8,
"selected": false,
"text": "print() sys.stdout.flush()"
},
{
"answer_id": 30682091,
"author": "kmario23",
"author_id": 2956066,
"author_profile": "https://Stackoverflow.com/users/2956066",
"pm_score": 3,
"selected": false,
"text": "'''To write to screen in real-time'''\nmessage = lambda x: print(x, flush=True, end=\"\")\nmessage('I am flushing out now...')\n"
},
{
"answer_id": 33265549,
"author": "Noah Krasser",
"author_id": 5243630,
"author_profile": "https://Stackoverflow.com/users/5243630",
"pm_score": 6,
"selected": false,
"text": "print() print(*objects, sep=' ', end='\\n', file=sys.stdout, flush=False)\n print(\"Visiting toilet\", flush=True)\n"
},
{
"answer_id": 35467658,
"author": "Russia Must Remove Putin",
"author_id": 541136,
"author_profile": "https://Stackoverflow.com/users/541136",
"pm_score": 8,
"selected": false,
"text": "print(..., flush=True) file.flush() sys.stdout print = partial(print, flush=True) -u PYTHONUNBUFFERED=TRUE flush=True print print('foo', flush=True) \n flush __future__ from __future__ import print_function\nimport sys\n\nif sys.version_info[:2] < (3, 3):\n old_print = print\n def print(*args, **kwargs):\n flush = kwargs.pop('flush', False)\n old_print(*args, **kwargs)\n if flush:\n file = kwargs.get('file', sys.stdout)\n # Why might file=None? IDK, but it works for print(i, file=None)\n file.flush() if file is not None else sys.stdout.flush()\n six file.flush() import sys\nprint 'delayed output'\nsys.stdout.flush()\n flush=True import functools\nprint = functools.partial(print, flush=True)\n >>> print = functools.partial(print, flush=True)\n>>> print\nfunctools.partial(<built-in function print>, flush=True)\n >>> print('foo')\nfoo\n >>> print('foo', flush=False)\nfoo\n print def foo():\n printf = functools.partial(print, flush=True)\n printf('print stuff like this')\n -u $ python -u script.py\n $ python -um package.module\n $ export PYTHONUNBUFFERED=TRUE\n C:\\SET PYTHONUNBUFFERED=TRUE\n flush >>> from __future__ import print_function\n>>> help(print)\nprint(...)\n print(value, ..., sep=' ', end='\\n', file=sys.stdout)\n \n Prints the values to a stream, or to sys.stdout by default.\n Optional keyword arguments:\n file: a file-like object (stream); defaults to the current sys.stdout.\n sep: string inserted between values, default a space.\n end: string appended after the last value, default a newline.\n"
},
{
"answer_id": 37242598,
"author": "user263387",
"author_id": 6338046,
"author_profile": "https://Stackoverflow.com/users/6338046",
"pm_score": 4,
"selected": false,
"text": "flush = True def print(*objects, sep=' ', end='\\n', file=sys.stdout, flush=True):\n __builtins__.print(*objects, sep=sep, end=end, file=file, flush=flush)\n"
},
{
"answer_id": 58741275,
"author": "Guillaume Mougeot",
"author_id": 10759078,
"author_profile": "https://Stackoverflow.com/users/10759078",
"pm_score": 3,
"selected": false,
"text": "for i in range(100000):\n print('{:s}\\r'.format(''), end='', flush=True)\n print('Loading index: {:d}/100000'.format(i+1), end='')\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8835/"
] |
230,755
|
<p>I have a user control that is pretty basic. It contains several TextBox controls, a few DropDownList controls, a save Button and a cancel Button. I would like to use this control in two different modes. The first mode is in the normal postback mode to do the save and cancel actions. The second mode would use AJAX to do the save and cancel actions.</p>
<p>Is it possible to wrap the contents of the control in an UpdatePanel and then be able to turn on/off whether or not the UpdatePanel does AJAX or PostBack for the control events? Or would I be better served by just creating two new controls (1 with UpdatePanel, 1 without) to house the one old control?</p>
|
[
{
"answer_id": 230772,
"author": "Zachary Yates",
"author_id": 8360,
"author_profile": "https://Stackoverflow.com/users/8360",
"pm_score": 0,
"selected": false,
"text": "void Page_Load() {\n if(IsAjaxy) {\n upAnUpdatePanel.Controls.Add(tbSomeTextBox);\n }\n else {\n this.Controls.Add(tbSomeTextBox);\n }\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230755",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30887/"
] |
230,759
|
<p>I assume that most of the analyzing and tracking is done based on the data gathered from browser actions like page requests. Tools like AWStats, Google Analytics and Omniture take place in this.</p>
<p>But there is also good amount of data available in databases or service level logs. For example GWT based application might be a bit tricky to analyze. Or in case of a financial application customer might be interested in suspicious transfers.</p>
<p>So, please share your best practices:</p>
<ul>
<li>What kind of approaches you have implemented for DB or log analysis?</li>
<li>Do you use some existing tools or your own in-house products?</li>
<li>Are you happy just to follow which functionality is the used most one and how fast it is processed?</li>
<li>Or do you actually store user action paths and use those to spot unusual patterns?</li>
</ul>
|
[
{
"answer_id": 230772,
"author": "Zachary Yates",
"author_id": 8360,
"author_profile": "https://Stackoverflow.com/users/8360",
"pm_score": 0,
"selected": false,
"text": "void Page_Load() {\n if(IsAjaxy) {\n upAnUpdatePanel.Controls.Add(tbSomeTextBox);\n }\n else {\n this.Controls.Add(tbSomeTextBox);\n }\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230759",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28841/"
] |
230,788
|
<p>I need to select from a table and filter on dates greater than a
specified date. </p>
<p>The problem I'm having is that the dates are stored as nchar(20) and I
can't seem to get it converted to date in the where clause. </p>
<pre><code>SELECT CONVERT(DATETIME,log_time,20) from dbo.logs
where CONVERT(DATETIME,log_time,20) > '10/20/2008'
</code></pre>
<p>Msg 241, Level 16, State 1, Line 1
Conversion failed when converting datetime from character string. </p>
|
[
{
"answer_id": 230802,
"author": "Nick Berardi",
"author_id": 17,
"author_profile": "https://Stackoverflow.com/users/17",
"pm_score": 0,
"selected": false,
"text": "select convert(datetime, cast(trim(log_time), nvarchar)) from dbo.logs\nwhere convert(datetime, cast(trim(log_time), nvarchar)) > '10/20/2008'\n"
},
{
"answer_id": 230854,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 1,
"selected": false,
"text": "select convert(datetime, cast(rtrim(log_time), nvarchar)) from dbo.logs\nwhere convert(datetime, cast(rtrim(log_time), nvarchar)) > '10/20/2008'\n"
}
] |
2008/10/23
|
[
"https://Stackoverflow.com/questions/230788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.